* @project ApPHP Business Directory * @copyright (c) 2011 ApPHP * @author ApPHP <*****@*****.**> * @license http://www.gnu.org/licenses/ */ // *** Make sure the file isn't accessed directly defined('APPHP_EXEC') or die('Restricted Access'); //-------------------------------------------------------------------------- if ($objLogin->IsLoggedInAsAdmin() && $objLogin->HasPrivileges('add_pages')) { if (isset($_REQUEST['language_id'])) { $language_id = prepare_input($_REQUEST['language_id']); $objSiteDescription->LoadData($language_id); } else { $language_id = Languages::GetDefaultLang(); } $wysiwyg_dir = Languages::GetLanguageDirection($language_id); $objPage = new Pages(); $link_target = isset($_POST['link_target']) ? prepare_input($_POST['link_target']) : '_self'; $tag_title = isset($_POST['tag_title']) ? prepare_input($_POST['tag_title']) : $objSiteDescription->GetParameter('tag_title'); $tag_keywords = isset($_POST['tag_keywords']) ? prepare_input($_POST['tag_keywords']) : $objSiteDescription->GetParameter('tag_keywords'); $tag_description = isset($_POST['tag_description']) ? prepare_input($_POST['tag_description']) : $objSiteDescription->GetParameter('tag_description'); $meta_tags_status = isset($_POST['meta_tags_status']) ? prepare_input($_POST['meta_tags_status']) : 'closed'; $copy_to_other_langs = isset($_POST['copy_to_other_langs']) ? prepare_input($_POST['copy_to_other_langs']) : 'yes'; $access_level = isset($_POST['access_level']) ? prepare_input($_POST['access_level']) : '0'; $show_in_search = isset($_POST['show_in_search']) ? prepare_input($_POST['show_in_search']) : '1'; $priority_order = isset($_POST['priority_order']) ? (int) $_POST['priority_order'] : $objPage->GetMaxOrder($language_id) + 1; $finish_publishing = isset($_POST['finish_publishing']) && check_date($_POST['finish_publishing']) ? prepare_input($_POST['finish_publishing']) : _NEVER; $is_published = isset($_POST['is_published']) ? prepare_input($_POST['is_published']) : '1'; $submit = isset($_POST['subSavePage']) ? prepare_input($_POST['subSavePage']) : ''; $act = isset($_POST['act']) ? prepare_input($_POST['act']) : ''; $msg = '';
public function DrawEditMode($rid = '0', $buttons = array('reset' => false, 'cancel' => true)) { $this->IncludeJSFunctions('edit'); $this->curRecordId = $rid; $sorting_fields = self::GetParameter('sorting_fields'); $sorting_types = self::GetParameter('sorting_types'); $page = self::GetParameter('page'); $operation = self::GetParameter('operation'); $operation_type = self::GetParameter('operation_type'); $operation_field = self::GetParameter('operation_field'); $search_status = self::GetParameter('search_status'); // prepare language direction for textboxes, textareas etc.. $language_dir = @Languages::GetLanguageDirection($this->languageId); $nl = "\n"; echo '<form name="frmMicroGrid_' . $this->tableName . '" id="frmMicroGrid_' . $this->tableName . '" action="' . $this->formActionURL . '" method="post" enctype="multipart/form-data">' . $nl; draw_hidden_field('mg_prefix', $this->uPrefix); echo $nl; draw_hidden_field('mg_action', 'update'); echo $nl; draw_hidden_field('mg_rid', $this->curRecordId); echo $nl; draw_hidden_field('mg_sorting_fields', $sorting_fields); echo $nl; draw_hidden_field('mg_sorting_types', $sorting_types); echo $nl; draw_hidden_field('mg_page', $page); echo $nl; draw_hidden_field('mg_operation', ''); echo $nl; draw_hidden_field('mg_operation_type', ''); echo $nl; draw_hidden_field('mg_operation_field', ''); echo $nl; draw_hidden_field('mg_search_status', $search_status); echo $nl; draw_hidden_field('mg_language_id', $this->languageId); echo $nl; draw_hidden_field('mg_operation_code', self::GetRandomString(20)); echo $nl; draw_token_field(); echo $nl; // save filter (search) data for view mode if ($this->isFilteringAllowed) { foreach ($this->arrFilteringFields as $key => $val) { //if($val['type'] == 'text'){ $filter_field_value = $search_status == 'active' ? self::GetParameter('filter_by_' . $val['table'] . $val['field'], false) : ''; draw_hidden_field('filter_by_' . $val['table'] . $val['field'], $filter_field_value); echo $nl; //} } } // 1. prepare password fields foreach ($this->arrEditModeFields as $key => $val) { if (preg_match('/separator/i', $key) && is_array($val)) { foreach ($val as $v_key => $v_val) { if ($v_key != 'separator_info') { // prepare password if (isset($v_val['type']) && ($v_val['type'] == 'password' || $this->IsSecureField($key, $v_val))) { $password_field = $this->UncryptValue($v_key, $v_val); $this->EDIT_MODE_SQL = str_replace($this->tableName . '.' . $v_key, $password_field, $this->EDIT_MODE_SQL); } } } } else { // prepare password if (isset($val['type']) && ($val['type'] == 'password' || $this->IsSecureField($key, $val))) { $password_field = $this->UncryptValue($key, $val); $this->EDIT_MODE_SQL = str_replace($this->tableName . '.' . $key, $password_field, $this->EDIT_MODE_SQL); } } } $this->EDIT_MODE_SQL = str_replace('_RID_', $this->curRecordId, $this->EDIT_MODE_SQL); if ($this->debug) { $start_time = $this->GetFormattedMicrotime(); } $this->result = database_query($this->EDIT_MODE_SQL, DATA_AND_ROWS); if ($this->debug) { $finish_time = $this->GetFormattedMicrotime(); } if ($this->debug) { $this->arrSQLs['select_edit_mode'] = '<i>Retrieve Edit Mode Record</i> | T: ' . round((double) $finish_time - (double) $start_time, 4) . ' sec. <br>' . $this->EDIT_MODE_SQL; } if (!$this->result[1]) { if ($this->debug) { echo $this->EDIT_MODE_SQL . '<br>' . mysql_error(); } else { echo _WRONG_PARAMETER_PASSED; } return false; } //---------------------------------------------------------------------- // perform operations before drawing Edit Mode $this->BeforeEditRecord(); // 1. draw hidden fields // 2. delete files/images foreach ($this->arrEditModeFields as $key => $val) { if (preg_match('/separator/i', $key) && is_array($val)) { foreach ($val as $v_key => $v_val) { if ($v_key != 'separator_info') { // delete file/image if ($operation == 'remove' && $operation_field != '' && $v_key == $operation_field) { $this->RemoveFileImage($this->curRecordId, $operation_field, $v_val['target'], $this->result[0][0][$v_key]); $this->result[0][0][$v_key] = ''; } // draw hidden field if ($v_val['type'] == 'hidden') { draw_hidden_field($v_key, isset($v_val['default']) && !empty($v_val['default']) ? $v_val['default'] : $this->result[0][0][$v_key]); echo $nl; } } } } else { // delete file/image if ($operation == 'remove' && $operation_field != '' && $key == $operation_field) { $this->RemoveFileImage($this->curRecordId, $operation_field, $val['target'], $this->result[0][0][$key]); $this->result[0][0][$key] = ''; } // draw hidden field if ($val['type'] == 'hidden') { draw_hidden_field($key, isset($val['default']) && !empty($val['default']) ? $val['default'] : $this->result[0][0][$key]); echo $nl; } } } // draw Edit Form echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="mgrid_table">' . $nl; if ($this->allowTopButtons) { $this->DrawEditModeButtons($buttons); } foreach ($this->arrEditModeFields as $key => $val) { if (preg_match('/separator/i', $key) && is_array($val)) { echo '</table><br>' . $nl; echo '<fieldset style="padding:5px;margin-left:5px;margin-right:10px;">' . $nl; $columns = isset($val['separator_info']['columns']) ? (int) $val['separator_info']['columns'] : 0; if (isset($val['separator_info']['legend'])) { echo '<legend>' . $val['separator_info']['legend'] . '</legend>' . $nl; } echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="mgrid_table">' . $nl; $row_count = 0; foreach ($val as $v_key => $v_val) { if (!$this->IsVisible($v_val)) { continue; } if ($v_key != 'separator_info' && $v_val['type'] != 'hidden') { if ($columns && $row_count % $columns == 0) { if ($row_count) { echo '</tr>' . $nl; } echo '<tr id="mg_row_' . $v_key . '" onmouseover="__mgTrOnMouseOver(this,\'' . Application::Get('defined_right') . '\')" onmouseout="__mgTrOnMouseOut(this,\'' . Application::Get('defined_right') . '\')">'; } else { if (!$columns) { echo '<tr id="mg_row_' . $v_key . '" onmouseover="__mgTrOnMouseOver(this,\'' . Application::Get('defined_right') . '\')" onmouseout="__mgTrOnMouseOut(this,\'' . Application::Get('defined_right') . '\')">'; } } echo '<td width="25%"><label for="' . $v_key . '">' . $v_val['title'] . '</label>'; $this->DrawRequiredAsterisk($v_val); $this->DrawHeaderTooltip($v_val); $this->DrawImageText($v_val); echo ':'; $this->DrawTextareaMaxlength($v_val); echo '</td>'; if (!$this->ParamEmpty($v_key) && $v_val['type'] != 'checkbox') { /* [#001 - 01.03.12] */ echo '<td style="padding-left:6px;">' . $this->DrawFieldByType('edit', $v_key, $v_val, $this->params, false, $language_dir) . '</td>'; } else { echo '<td style="padding-left:6px;">' . $this->DrawFieldByType('edit', $v_key, $v_val, $this->result[0][0], false, $language_dir) . '</td>'; } if (!$columns) { echo '</tr>' . $nl; } $row_count++; } } echo '</table>' . $nl; echo '</fieldset>' . $nl; echo '<table width="100%" border="0" cellspacing="0" cellpadding="2" class="mgrid_table">' . $nl; } else { if (!$this->IsVisible($val)) { continue; } if ($val['type'] != 'hidden') { echo '<tr id="mg_row_' . $key . '" onmouseover="__mgTrOnMouseOver(this,\'' . Application::Get('defined_right') . '\')" onmouseout="__mgTrOnMouseOut(this,\'' . Application::Get('defined_right') . '\')">'; echo '<td width="25%"><label for="' . $key . '">' . $val['title'] . '</label>'; $this->DrawRequiredAsterisk($val); $this->DrawHeaderTooltip($val); $this->DrawImageText($val); echo ':'; $this->DrawTextareaMaxlength($val); echo '</td>'; if (!$this->ParamEmpty($key) && $val['type'] != 'checkbox') { /* [#001 - 01.03.12] */ echo '<td style="padding-left:6px;">' . $this->DrawFieldByType('edit', $key, $val, $this->params, false, $language_dir) . '</td>'; } else { echo '<td style="padding-left:6px;">' . $this->DrawFieldByType('edit', $key, $val, $this->result[0][0], false, $language_dir) . '</td>'; } echo '</tr>' . $nl; } } } $this->DrawEditModeButtons($buttons); echo '</table><br>' . $nl; echo '</form>' . $nl; if ($this->errorField != '') { echo '<script type="text/javascript">__mgSetFocus(\'' . $this->errorField . '\');</script>'; } $this->AfterEditRecord(); $this->DrawVersionInfo(); $this->DrawRunningTime(); $this->DrawErrors(); $this->DrawWarnings(); $this->DrawSQLs(); $this->DrawPostInfo(); }
/** * Draws Edit Form * @param $key * @param $draw */ public function DrawEditForm($key = '0', $draw = true) { $total_languages = Languages::GetAllLanguages(); $key_value = $key_text = ''; $default_lang_name = 'English'; $default_lang_abbr = 'en'; $lang_to_dir = Languages::GetLanguageDirection($this->languageId); $default_lang_text = ''; $align_left = Application::Get('lang_dir') == 'ltr' ? 'left' : 'right'; $align_right = Application::Get('lang_dir') == 'ltr' ? 'right' : 'left'; $output = ''; $sql = 'SELECT * FROM ' . TABLE_VOCABULARY . ' WHERE id = ' . (int) $key; if ($row = database_query($sql, DATA_ONLY, FIRST_ROW_ONLY)) { $key_value = $row['key_value']; $key_text = $row['key_text']; $this->currentKey = $key_value; } $sql = 'SELECT * FROM ' . TABLE_LANGUAGES . ' WHERE is_default = 1'; if ($row = database_query($sql, DATA_ONLY, FIRST_ROW_ONLY)) { $default_lang_name = $row['lang_name']; $default_lang_abbr = $row['abbreviation']; $sql = 'SELECT * FROM ' . TABLE_VOCABULARY . ' WHERE key_value = \'' . $this->currentKey . '\' AND language_id = \'' . $default_lang_abbr . '\''; if ($row = database_query($sql, DATA_ONLY, FIRST_ROW_ONLY)) { $default_lang_text = strip_tags($row['key_text'], '<b><i><u><br>'); } } if ($default_lang_abbr != $this->languageId) { $output .= '<script type="text/javascript"> google.load("language", "1"); function TranslateText(response){ if(response.data){ jQuery("#txt_message").html("' . _COMPLETED . '!"); jQuery("#txt_key_value").val(response.data.translations[0].translatedText); jQuery("#btnTranslate").attr("disabled", false); }else{ //response.error.message jQuery("#txt_message").html("This feature is only available for Google paid accounts! Please check you have a valid API Key."); } } function GoAndTranslate(){'; // Block all operations in demo mode if (strtolower(SITE_MODE) == 'demo') { $output .= 'alert(\'' . _OPERATION_BLOCKED . '\'); return false; '; } else { $output .= '// grabbing the text to translate var YOUR_API_KEY = ""; var text = jQuery("#txt_key_value").val(); if(text.indexOf(" ") <= 0) text = text.toLowerCase(); jQuery("#btnTranslate").attr("disabled", true); jQuery("#txt_message").html(""); var newScript = document.createElement("script"); newScript.type = "text/javascript"; // WARNING: be aware that YOUR-API-KEY inside html is viewable by all your users. // Restrict your key to designated domains or use a proxy to hide your key // to avoid misuage by other party. var source = "https://www.googleapis.com/language/translate/v2?key="+YOUR_API_KEY+"&source=' . $default_lang_abbr . '&target=' . $this->languageId . '&callback=TranslateText&q=" + text; newScript.src = source; // When we add this script to the head, the request is sent off. document.getElementsByTagName("head")[0].appendChild(newScript);'; } $output .= '} </script>'; } $output .= '<form action="index.php?admin=vocabulary" method="post">'; $output .= draw_hidden_field('submition_type', '1', false); $output .= draw_hidden_field('key', $key, false); $output .= draw_hidden_field('filter_by', $this->filterBy, false); $output .= draw_hidden_field('language_id', $this->languageId, false); $output .= draw_token_field(false); $output .= '<table align="center" width="99%" border="0" cellspacing="0" cellpadding="3" class="main_text"> <tr valign="top"> <td><b>' . _EDIT_WORD . '</b></td> <td><div id="txt_message" style="color:#00a600"></div></td> <td width="20px" nowrap="nowrap"></td> <td align="' . $align_right . '">' . draw_languages_box('language_id', $total_languages[0], 'abbreviation', 'lang_name', $this->languageId, '', 'disabled="disabled"', false) . '</td> </tr> <tr valign="top"> <td align="' . $align_right . '" width="90px">' . _KEY . ':</td> <td align="' . $align_left . '" colspan="2"> ' . $key_value . ' ' . draw_hidden_field('txt_key', $key_value, false) . ' </td> <td></td> </tr>'; $output .= '<tr valign="top"> <td align="' . $align_right . '">' . _VALUE . ' <span style="color:#c13a3a">*</span>:</td> <td align="' . $align_left . '"> <textarea dir="' . $lang_to_dir . '" style="width:100%;height:60px;overflow:auto;padding:3px;" name="txt_key_value" id="txt_key_value" maxlength="4096">' . decode_text($key_text) . '</textarea> </td> <td></td> <td align="right" width="240px">'; if ($default_lang_abbr != $this->languageId) { $output .= '<nobr> ' . $default_lang_name . ' » ' . strtoupper($this->languageId) . ' <input class="form_button" type="button" id="btnTranslate" name="submit" style="width:150px" onclick="GoAndTranslate()" value="' . _TRANSLATE_VIA_GOOGLE . '" /> <input class="form_button" type="reset" name="btnReset" title="' . _RESET . '" value="R" /> </nobr><br /><br />'; } $output .= '<input class="form_button" type="submit" name="submit" value="' . decode_text(_BUTTON_UPDATE) . '"> <input class="form_button" type="button" onclick="appGoTo(\'admin=vocabulary' . $this->langIdByUrl . $this->filterByUrl . '\')" value="' . decode_text(_BUTTON_CANCEL) . '"> </td> </tr>'; if ($default_lang_abbr != $this->languageId) { $output .= '<tr valign="top"> <td align="' . $align_right . '" width="110px">' . $default_lang_name . ':</td> <td align="' . $align_left . '">' . $default_lang_text . '</td> <td colspan="2"></td> </tr>'; } $output .= '<tr align="right"><td colspan="4"></td></tr> </table> </form>'; if ($draw) { echo $output; } else { return $output; } }