<?php
/**
 * Edit language files
 *
 * Edit language files for root and members language files. Admin can see the language phrases for each language
 * variable and they can edit the language phrases and update their own new language phrases.
 * First available languages will be listed then the folder list will be there.
 * Admin can choose language option and directory. After submit the corresponding folder file list
 * would be listed. Admin can choose one of files and can submit.
 * After submit the corresponding file language variable and phrases would be listed.
 * Admin can edit the phrases but there should not be any ' symbol that may afect script.
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###Edit language###
 * @author 		selvaraj_47ag04
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id:
 * @since 		2008-12-22
 */
/**
 * Config file
 */
require_once('../common/configs/config.inc.php');
$CFG['lang']['include_files'][]                = 'languages/%s/admin/editLanguageFile.php';
$CFG['html']['header']                         = 'admin/html_header.php';
$CFG['html']['footer']                         = 'admin/html_footer.php';
//compulsory
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header']                  = false;
/**
 * To include application top file
 */
require($CFG['site']['project_path'] . 'common/application_top.inc.php');
//------------------- Class EditLanguageHandler begins ------------------->>>>>//
/**
 * Edit language
 */
//<<<<<------------------ Class EditLanguageHandler ends --------------------//
class EditLanguageHandler extends FormHandler {
    /**
     * Populate given List
     *
     * @param		array $list_arr list array
     * @param		string $highlight_value
     * @return		void
     * @access		public
     */
    public function populateList($list_arr, $highlight_value = '') {
        foreach ($list_arr as $key => $value) {
?>

<option value="<?php
            echo $key;
?>"<?php
            echo ($highlight_value == $key) ? ' selected="selected"' : '';
?>><?php
            echo $value;
?></option>
<?php
        }
    }
    /**
     * Populate hidden form fields
     *
     * Populate hidden form fields for the array of fields
     *
     * @param		array $field_names_arr the array of fields
     * @return		void
     * @access		public
     **/
    public function populateHiddenFormFields($field_names_arr = array()) {
        foreach ($field_names_arr as $field_name) {
            if (is_array($this->fields_arr[$field_name])) {
                foreach ($this->fields_arr[$field_name] as $sub_field_value) {
?>
<input type="hidden" name="<?php
                    echo $field_name;
?>[]" value="<?php
                    echo $sub_field_value;
?>" />
<?php
                }
            } else {
?>
<input type="hidden" name="<?php
                echo $field_name;
?>" value="<?php
                echo $this->fields_arr[$field_name];
?>" />
<?php
            }
        }
    }
    /**
     * Sets directory path
     *
     * Sets directory path
     *
     * @param		array $dir_path_arr directory path list
     * @return 		void
     * @access		public
     */
    public function setDirectoryPath($dir_path_arr) {
        $this->dir_path_arr = $dir_path_arr;
    }
    /**
     * Populate File names list
     *
     * Populate File names list for select folder
     *
     * @param		string $highlight_value highlight value
     * @param		string $unwanted_files_list_arr unwanted fils list
     * @return 		void
     * @access		public
     */
    public function populateFileNamesList($highlight_value, $unwanted_files_list_arr) {
        if ($handle = opendir($this->dir_path_arr[$this->fields_arr['directory']] . $this->fields_arr['language'] . '/' . $this->fields_arr['directory'] . '/')) {
            /* This is the correct way to loop over the directory. */
            while (($file = readdir($handle)) !== false) {
                if (strpos($file, '.php') !== false and (array_search($file, $unwanted_files_list_arr) === false)) {
?>
<option value="<?php
                    echo $file;
?>"<?php
                    echo ($file == $highlight_value) ? ' selected="selected"' : '';
?>><?php
                    echo $file;
?></option>
<?php
                }
            }
            closedir($handle);
        }
    }
    /**
     * Check is from list
     *
     * Check is from valid array value
     *
     * @param		array $option_arr
     * @param		string $field_name field name
     * @param		string $err_tip error tip
     * @return 		boolean true/false
     * @access		public
     */
    public function chkIsFromList($option_arr, $field_name, $err_tip = '') {
        $is_ok = isset($option_arr[$this->fields_arr[$field_name]]);
        if (!$is_ok)
            $this->fields_err_tip_arr[$field_name] = $err_tip;
        return $is_ok;
    }
    /**
     * Check is file exist
     *
     * Check is file exist to find valid file
     *
     * @param		string $file file field name
     * @param		string $unwanted_files_list_arr unwanted fils list
     * @param		string $err_tip error tip
     * @return 		boolean true/false
     * @access		public
     */
    public function chkIsFileExist($file, $unwanted_files_list_arr, $err_tip, $read_err_tip, $write_err_tip) {
        // set file name with path
        $file_path = $this->dir_path_arr[$this->fields_arr['directory']] . $this->fields_arr['language'] . '/' . $this->fields_arr['directory'] . '/' . $this->fields_arr[$file];
        //read file content
        $is_ok     = ((array_search($this->fields_arr[$file], $unwanted_files_list_arr) === false) and file_exists($file_path));
        if (!$is_ok)
            $this->fields_err_tip_arr[$file] = $err_tip;
        else if (!is_readable($file_path))
            $this->fields_err_tip_arr[$file] = $read_err_tip;
        else if (!is_writable($file_path))
            $this->fields_err_tip_arr[$file] = $write_err_tip;
        return $is_ok;
    }
    /**
     * Update file content
     *
     * Update edited file content
     *
     * @param		array $post_arr post array
     * @return 		void
     * @access		public
     * @todo		Need to check and improve find and replacement. Because some time the
     * 				language file has special characters too.
     */
    public function updateFileContent($post_arr) {
        // set file name with path
        $file_path = $this->dir_path_arr[$this->fields_arr['directory']] . $this->fields_arr['language'] . '/' . $this->fields_arr['directory'] . '/' . $this->fields_arr['file'];
        //read file content
        $content   = file_get_contents($file_path);
        //include the file as
        require($file_path);
        // checks whether file edited
        $is_file_edited = false;
        foreach ($post_arr as $varname => $value) {
            // checks variable value has been changed
            if (isset($LANG[$varname]) and isset($post_arr[$varname]) and $LANG[$varname] != $post_arr[$varname]) {
                $is_file_edited       = true;
                // replace value of file content
                // vaiable start pos
                $variable_start       = strpos($content, $varname, 0);
                // vaiable end pos
                $end_of_variable      = strpos($content, '=', $variable_start) + 1;
                // get content before value
                $content_before_value = trim(substr($content, 0, $end_of_variable));
                // vaiable line end pos
                $variable_end_pos     = strpos($content, ';', $end_of_variable);
                // get content after value
                $content_after_value  = trim(substr($content, $variable_end_pos));
                // new content+
                $content              = $content_before_value . ' \'' . addslashes($post_arr[$varname]) . '\'' . $content_after_value;
            }
        }
        if ($is_file_edited) {
            $fw = fopen($file_path, 'w');
            fwrite($fw, $content);
            fclose($fw);
        }
    }
    /**
     * Update FAQ
     *
     * Update FAQ into faq list array
     *
     * @param		string $question question array name
     * @param		string $answer answer array name
     * @return 		void
     * @access		public
     */
    public function updateFAQIntoFAQListArray($question, $answer) {
        // set file name with path
        $file_path = sprintf($this->dir_path_arr[$this->fields_arr['directory']], $this->fields_arr['language']);
        //read file content
        $content   = file_get_contents($file_path);
        //include the file as
        $comments  = substr($content, strpos($content, '/**'), (strrpos($content, '*/') - strpos($content, '/**') + 2));
        // set array
        $arraycode = '<?php ' . "\n\n" . $comments . "\n\n" . '$LANG_LIST_ARR[\'faq\'] = array(' . "\n";
        foreach ($this->fields_arr[$question] as $key => $value) {
            if ($value)
                $arraycode .= '\'' . addslashes($value) . '\' => ' . '\'' . addslashes((isset($this->fields_arr[$answer][$key])) ? $this->fields_arr[$answer][$key] : '') . '\', ' . "\r\n";
        }
        $arraycode = substr($arraycode, 0, strrpos($arraycode, ','));
        $arraycode .= "\n" . '); ' . "\n" . '?>';
        // write in to the FAQ list array
        $fw = fopen($file_path, 'w');
        fwrite($fw, $arraycode);
        fclose($fw);
    }
    /**
     * EditLanguageHandler::stripslashesNew()
     *
     * @param mixed $value
     * @return
     */
    public function stripslashesNew($value) {
        $value = str_replace('\\', '~*@', $value);
        $value = stripslashes($value);
        $value = str_replace('~*@', '\\', $value);
        $value = str_replace('\"', '"', $value);
        return $value;
    }
    /**
     * EditLanguageHandler::getLanguagesList()
     *
     * @return
     */
    public function getLanguagesList() {
        $directory_list = readDirectory($this->CFG['site']['project_path'] . 'languages/', 'dir');
        $languages_arr  = array();
        foreach ($directory_list as $value) {
            $languages_arr[$value] = $value;
        }
        return $languages_arr;
    }
}
//<<<<<<<---------------------------class EditLanguageHandler--------------------//
//-------------------------------------Code begins-------------------------->>>>>//
$editLanguageObj = new EditLanguageHandler();
//set blocks
$editLanguageObj->setPageBlockNames(array(
    'block_msg_form_success',
    'block_msg_form_error',
    'block_form_directory_list',
    'block_form_files_list',
    'block_form_edit_phrases',
    'block_page_list_phrases',
    'block_form_faq_list'
));
//set Form Fields
$editLanguageObj->setFormField('language', $CFG['lang']['default']);
$editLanguageObj->setFormField('directory', 'root');
$editLanguageObj->setFormField('file', '');
$editLanguageObj->setFormField('success_msg', '');
$editLanguageObj->setFormField('question', array());
$editLanguageObj->setFormField('answer', array());
$editLanguageObj->setFormField('add_new_faq', 0);
$editLanguageObj->setFormField('action', '');
$CFG['lang']['available_languages'] = $editLanguageObj->getLanguagesList();
// folders languate //'faq' => $LANG['langedit_faq']
$lang_folders_arr                   = array(
    'root' => $LANG['langedit_root'],
    'members' => $LANG['members'],
    'admin' => $LANG['common_user_access_admin'],
    'general' => $LANG['langedit_general'],
    'common' => $LANG['langedit_common'],
    'answers' => $LANG['langedit_anova'],
    'answers/admin' => $LANG['langedit_anova_admin']
);
// set directory path
$directory_path_arr                 = array(
    'root' => '../languages/',
    'members' => '../languages/',
    'admin' => '../languages/',
    'general' => '../languages/',
    'common' => '../languages/',
    'answers' => '../languages/',
    'answers/admin' => '../languages/'
);
// set directory path
$editLanguageObj->setDirectoryPath($directory_path_arr);
// set unwanted file list
$unwanted_files_list_arr = array(
    'html_header.php',
    'html_footer.php',
    'accessibility.php',
    'useTerms.php',
    'privacyPolicy.php',
    'email_notify.inc.php',
    'help.inc.php'
);
// Hide All Blocks and show default page
$editLanguageObj->setAllPageBlocksHide();
$editLanguageObj->setPageBlockShow('block_form_directory_list');
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_cancel')) {
    Redirect2Url('index.php');
}
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_back_files') or $editLanguageObj->isFormPOSTed($_POST, 'submit_back_faq')) {
    $editLanguageObj->sanitizeFormInputs($_POST);
    $editLanguageObj->setAllPageBlocksHide();
    $editLanguageObj->setPageBlockShow('block_form_directory_list');
}
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_back_phrases')) {
    $editLanguageObj->sanitizeFormInputs($_POST);
    $editLanguageObj->setAllPageBlocksHide();
    $editLanguageObj->setPageBlockShow('block_form_files_list');
}
// Submit directory
if (isDemoSite() AND $editLanguageObj->isFormPOSTed($_POST, 'submit_directory')) {
    $editLanguageObj->setAllPageBlocksHide();
    $editLanguageObj->setPageBlockShow('block_form_directory_list');
    $editLanguageObj->setPageBlockShow('block_msg_form_error');
    $editLanguageObj->setCommonErrorMsg($LANG['no_permission_for_demo_user']);
} elseif ($editLanguageObj->isFormPOSTed($_POST, 'submit_directory')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_POST);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    // check valid form inputs
    if ($editLanguageObj->isValidFormInputs()) {
        if ($editLanguageObj->getFormField('directory') != 'faq') {
            // Hide All Blocks and show default page
            $editLanguageObj->setAllPageBlocksHide();
            $editLanguageObj->setPageBlockShow('block_form_files_list');
        } else {
            // Hide All Blocks and show default page
            $editLanguageObj->setAllPageBlocksHide();
            $editLanguageObj->setPageBlockShow('block_form_faq_list');
            // include the FAQ file
            require(sprintf($directory_path_arr[$editLanguageObj->getFormField('directory')], $editLanguageObj->getFormField('language')));
        }
    } else {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_directory_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_error');
    }
}
// submit file
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_files')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_POST);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('file', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFileExist('file', $unwanted_files_list_arr, $LANG['err_tip_invalid_file'], $LANG['langedit_read_err_tip_invalid'], $LANG['langedit_write_err_tip_invalid']);
    if ($editLanguageObj->isValidFormInputs()) {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_edit_phrases');
    } else {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_files_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_error');
    }
}
// submit file
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_phrases')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_POST);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('file', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFileExist('file', $unwanted_files_list_arr, $LANG['err_tip_invalid_file'], $LANG['langedit_read_err_tip_invalid'], $LANG['langedit_write_err_tip_invalid']);
    // update file content
    $editLanguageObj->updateFileContent($_POST);
    // Hide All Blocks and show default page
    $editLanguageObj->setAllPageBlocksHide();
    $editLanguageObj->setPageBlockShow('block_form_directory_list');
    $editLanguageObj->setPageBlockShow('block_msg_form_success');
    $editLanguageObj->setPageBlockShow('block_page_list_phrases');
    $editLanguageObj->setFormField('success_msg', sprintf($LANG['langedit_msg_success'], $editLanguageObj->getFormField('file')));
}
// Submit directory
if ($editLanguageObj->isFormPOSTed($_GET, 'language') and $editLanguageObj->isFormPOSTed($_GET, 'directory')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_GET);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    // check valid form inputs
    if ($editLanguageObj->isValidFormInputs()) {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_files_list');
    } else {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_directory_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_error');
    }
}
// add faq
if ($editLanguageObj->isFormPOSTed($_GET, 'action')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_POST);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    if ($editLanguageObj->isValidFormInputs()) {
        if ($editLanguageObj->getFormField('action') == 'addFAQ')
            $editLanguageObj->setFormField('add_new_faq', $editLanguageObj->getFormField('add_new_faq') + 1);
        // include the FAQ file
        require(sprintf($directory_path_arr[$editLanguageObj->getFormField('directory')], $editLanguageObj->getFormField('language')));
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_faq_list');
    } else {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_faq_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_error');
    }
}
// submit faq
if ($editLanguageObj->isFormPOSTed($_POST, 'submit_faq')) {
    // sanitize for inputs
    $editLanguageObj->sanitizeFormInputs($_POST);
    // validation
    $editLanguageObj->chkIsNotEmpty('language', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($CFG['lang']['available_languages'], 'language', $LANG['err_tip_invalid_file']);
    $editLanguageObj->chkIsNotEmpty('directory', $LANG['err_tip_compulsory']) and $editLanguageObj->chkIsFromList($lang_folders_arr, 'directory', $LANG['err_tip_invalid_file']);
    if ($editLanguageObj->isValidFormInputs()) {
        // update file content
        $editLanguageObj->updateFAQIntoFAQListArray('question', 'answer');
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_directory_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_success');
        $editLanguageObj->setFormField('success_msg', $LANG['langedit_faq_edit_success']);
    } else {
        // Hide All Blocks and show default page
        $editLanguageObj->setAllPageBlocksHide();
        $editLanguageObj->setPageBlockShow('block_form_faq_list');
        $editLanguageObj->setPageBlockShow('block_msg_form_error');
    }
}
//<<<<--------------------------------Code Ends-----------------------------//
//--------------------Page block templates begins-------------------->>>>>>>>>//
//include the header file
$editLanguageObj->includeHeader();
?>
<div id="selHelpLangEdit">
  <div id="selManageLaguageFile">
    <h2><?php
echo $LANG['langedit_lang_editing'];
?></h2>
    <p class="clsSettingInfo"><?php
echo $LANG['general_config_hint'];
?></p>
    <?php
if ($editLanguageObj->isShowPageBlock('block_msg_form_error')) {
?>
    <div id="selMsgError">
      <p><?php
    echo $LANG['common_msg_error_sorry'] . ' ' . $editLanguageObj->getCommonErrorMsg();
?></p>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_msg_form_success')) {
?>
    <div id="selMsgSuccess">
      <p><?php
    echo $editLanguageObj->getFormField('success_msg');
?></p>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_form_directory_list')) {
?>
    <div id="selDirectoryList">
      <form name="block_form_directory_list" id="block_form_directory_list" method="post" action="editLanguageFile.php">
        <table class="clsFormSection">
          <tr class="clsFormRow">
            <td class="<?php
    echo $editLanguageObj->getCSSFormLabelCellClass('language');
?>">
              <label for="selLanguage"><?php
    echo $LANG['langedit_language'];
?></label>
            </td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('language');
?>"><?php
    echo $editLanguageObj->getFormFieldErrorTip('language');
?>
              <select name="language" id="selLanguage" tabindex="1000">
                <?php
    $editLanguageObj->populateList($CFG['lang']['available_languages'], $editLanguageObj->getFormField('language'));
?>
              </select>
            </td>
          </tr>
          <tr class="clsFormRow">
            <td class="<?php
    echo $editLanguageObj->getCSSFormLabelCellClass('directory');
?>">
              <label for="selDirectory"><?php
    echo $LANG['langedit_directory'];
?></label>
            </td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('directory');
?>"><?php
    echo $editLanguageObj->getFormFieldErrorTip('directory');
?>
              <select name="directory" id="selDirectory" tabindex="1005">
                <?php
    $editLanguageObj->populateList($lang_folders_arr, $editLanguageObj->getFormField('directory'));
?>
              </select>
            </td>
          </tr>
          <tr class="clsFormRow">
            <td></td>
			<td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('submit');
?>">
              <input type="submit" class="clsSubmitButton" name="submit_directory" id="submit_directory" value="<?php
    echo $LANG['common_submit'];
?>" tabindex="1010" />
			  <input type="submit" class="clsCancelButton" name="submit_cancel" id="submit_cancel" value="<?php
    echo $LANG['common_cancel'];
?>" tabindex="1011" />
            </td>
          </tr>
        </table>
      </form>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_form_files_list')) {
?>
    <div id="selFilesList">
      <form name="block_form_files_list" id="block_form_files_list" method="post" action="editLanguageFile.php">
        <table class="clsFormSection">
          <tr class="clsFormRow">
            <td class="<?php
    echo $editLanguageObj->getCSSFormLabelCellClass('language');
?>">
              <label for="selLanguage"><?php
    echo $LANG['langedit_language'];
?></label>
            </td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('language');
?>"><?php
    echo $CFG['lang']['available_languages'][$editLanguageObj->getFormField('language')];
?></td>
          </tr>
          <tr class="clsFormRow">
            <td class="<?php
    echo $editLanguageObj->getCSSFormLabelCellClass('directory');
?>">
              <label for="selDirectory"><?php
    echo $LANG['langedit_directory'];
?></label>
            </td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('directory');
?>"><?php
    echo $lang_folders_arr[$editLanguageObj->getFormField('directory')];
?></td>
          </tr>
          <tr class="clsFormRow">
            <td class="<?php
    echo $editLanguageObj->getCSSFormLabelCellClass('file');
?>">
              <label for="selFile"><?php
    echo $LANG['langedit_file'];
?></label>
            </td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('file');
?>"><?php
    echo $editLanguageObj->getFormFieldErrorTip('file');
?>
              <select name="file" id="selFile" tabindex="1000">
                <?php
    $editLanguageObj->populateFileNamesList($editLanguageObj->getFormField('file'), $unwanted_files_list_arr);
?>
              </select>
            </td>
          </tr>
          <tr class="clsFormRow">
           	<td></td>
		    <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('submit');
?>">
              <?php
    $editLanguageObj->populateHiddenFormFields(array(
        'language',
        'directory'
    ));
?>
              <input type="submit" class="clsSubmitButton" name="submit_files" id="selSubmitFiles" value="<?php
    echo $LANG['common_submit'];
?>" tabindex="1005" />
			  <input type="submit" class="clsSubmitButton" name="submit_back_files" id="submit_back_files" value="<?php
    echo $LANG['langedit_back'];
?>" tabindex="1006" />
            </td>
          </tr>
        </table>
      </form>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_form_edit_phrases')) {
?>
    <div id="selEditForm">
      <h3><a href="editLanguageFile.php"><?php
    echo $CFG['lang']['available_languages'][$editLanguageObj->getFormField('language')];
?></a>/<a href="<?php
    echo 'editLanguageFile.php?language=' . $editLanguageObj->getFormField('language') . '&amp;directory=' . $editLanguageObj->getFormField('directory') . '&amp;file=' . $editLanguageObj->getFormField('file');
?>"><?php
    echo $lang_folders_arr[$editLanguageObj->getFormField('directory')];
?></a><?php
    echo '/' . $editLanguageObj->getFormField('file');
?></h3>
      <form name="editFrm" id="editFrm" method="post" action="editLanguageFile.php">
        <table class="clsFormSection">
          <tr class="clsFormRow">
            <td class="clsFormLabelCellDefault clsFormTableTitle"><?php
    echo $LANG['langedit_variable_name'];
?></td>
            <td class="clsFormFieldCellDefault clsFormTableTitle"><?php
    echo $LANG['langedit_new_value'];
?></td>
          </tr>
          <?php
    $lang_update = $LANG['common_update'];
    unset($LANG);
    // include the file
    require($directory_path_arr[$editLanguageObj->getFormField('directory')] . $editLanguageObj->getFormField('language') . '/' . $editLanguageObj->getFormField('directory') . '/' . $editLanguageObj->getFormField('file'));
    // populate phrases
    foreach ($LANG as $key => $value) {
?>
          <tr class="clsFormRow">
            <td class="<?php
        echo $editLanguageObj->getCSSFormLabelCellClass('varable');
?>">
              <label for="<?php
        echo $key;
?>"><?php
        echo $key;
?></label>
            </td>
            <td class="<?php
        echo $editLanguageObj->getCSSFormFieldCellClass('phrase');
?>">
              <textarea name="<?php
        echo $key;
?>" id="<?php
        echo $key;
?>" tabindex="1000" rows="3" cols="50"><?php
        echo $editLanguageObj->stripslashesNew($value);
?></textarea>
            </td>
          </tr>
          <?php
    }
?>
          <tr class="clsFormRow">
		  <td></td>
            <td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('submit');
?>">
              <?php
    $editLanguageObj->populateHiddenFormFields(array(
        'language',
        'directory',
        'file'
    ));
?>
              <input type="submit" class="clsSubmitButton" name="submit_phrases" id="selSubmitPhrases" value="<?php
    echo $lang_update;
?>" tabindex="1005" />
			  <input type="submit" class="clsSubmitButton" name="submit_back_phrases" id="submit_back_phrases" value="<?php
    echo $editLanguageObj->LANG['langedit_back'];
?>" tabindex="1006" />
            </td>
          </tr>
        </table>
      </form>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_page_list_phrases')) {
?>
    <div id="selPhrasesList">
      <h3><?php
    echo $CFG['lang']['available_languages'][$editLanguageObj->getFormField('language')] . '/' . $lang_folders_arr[$editLanguageObj->getFormField('directory')] . '/' . $editLanguageObj->getFormField('file');
?></h3>
      <table class="clsFormSection">
        <tr class="clsFormRow">
          <td class="clsFormLabelCellDefault"><?php
    echo $LANG['langedit_variable_name'];
?></td>
          <td class="clsFormFieldCellDefault"><?php
    echo $LANG['langedit_new_value'];
?></td>
        </tr>
        <?php
    unset($LANG);
    // include the file
    require($directory_path_arr[$editLanguageObj->getFormField('directory')] . $editLanguageObj->getFormField('language') . '/' . $editLanguageObj->getFormField('directory') . '/' . $editLanguageObj->getFormField('file'));
    // populate phrases
    foreach ($LANG as $key => $value) {
?>
        <tr class="clsFormRow">
          <td><?php
        echo $key;
?></td>
          <td><?php
        echo $editLanguageObj->stripslashesNew($value);
?></td>
        </tr>
        <?php
    }
?>
      </table>
    </div>
    <?php
}
if ($editLanguageObj->isShowPageBlock('block_form_faq_list')) {
?>
    <div id="selEditForm">
      <p><a href="<?php
    echo 'editLanguageFile.php?action=addFAQ&amp;directory=' . $editLanguageObj->getFormField('directory') . '&amp;language=' . $editLanguageObj->getFormField('language');
?>"><?php
    echo $LANG['langedit_add_faq'];
?></a></p>
      <p><?php
    echo $LANG['langedit_faq_delete_note'];
?></p>
      <form name="form_edit_faq" id="form_edit_faq" method="post" action="editLanguageFile.php">
        <input type="hidden" name="add_new_faq" value="<?php
    echo $editLanguageObj->getFormField('add_new_faq');
?>" />
        <input type="hidden" name="directory" value="<?php
    echo $editLanguageObj->getFormField('directory');
?>" />
        <input type="hidden" name="language" value="<?php
    echo $editLanguageObj->getFormField('language');
?>" />
        <table class="clsFormSection">
          <tr class="clsFormRow">
            <td class="clsFormLabelCellDefault"><?php
    echo $LANG['questions'];
?></td>
            <td class="clsFormFieldCellDefault"><?php
    echo $LANG['answers'];
?></td>
          </tr>
          <?php
    // populate phrases
    foreach ($LANG_LIST_ARR['faq'] as $key => $value) {
?>
          <tr class="clsFormRow">
            <td class="<?php
        echo $editLanguageObj->getCSSFormFieldCellClass('question');
?>">
              <textarea name="question[]" tabindex="1000" rows="3" cols="50"><?php
        echo $key;
?></textarea>
            </td>
            <td class="<?php
        echo $editLanguageObj->getCSSFormFieldCellClass('answer');
?>">
              <textarea name="answer[]" tabindex="1000" rows="3" cols="50"><?php
        echo $value;
?></textarea>
            </td>
          </tr>
          <?php
    }
    // populate phrases
    for ($i = 0; $i < $editLanguageObj->getFormField('add_new_faq'); $i++) {
?>
          <tr class="clsFormRow">
            <td class="<?php
        echo $editLanguageObj->getCSSFormFieldCellClass('question');
?>">
              <textarea name="question[]" tabindex="1000" rows="3" cols="50"></textarea>
            </td>
            <td class="<?php
        echo $editLanguageObj->getCSSFormFieldCellClass('answer');
?>">
              <textarea name="answer[]" tabindex="1000" rows="3" cols="50"></textarea>
            </td>
          </tr>
          <?php
    }
?>
          <tr class="clsFormRow">
            <td></td>
			<td class="<?php
    echo $editLanguageObj->getCSSFormFieldCellClass('submit');
?>">
              <?php
    $editLanguageObj->populateHiddenFormFields(array(
        'language',
        'directory',
        'file'
    ));
?>
              <input type="submit" class="clsSubmitButton" name="submit_faq" id="selSubmitFaq" value="<?php
    echo $LANG['common_update'];
?>" tabindex="1005" />
			  <input type="submit" class="clsSubmitButton" name="submit_back_faq" id="submit_back_faq" value="<?php
    echo $LANG['langedit_back'];
?>" tabindex="1006" />
            </td>
          </tr>
        </table>
      </form>
    </div>
    <?php
}
?>
  </div>
</div>
<?php
//<<<<<<--------------------Page block templates Ends--------------------//
$editLanguageObj->includeFooter();
?>