protected function _Load() { if (null === $this->wikiparser) { // Plain standard parsing can use the efficient ajax url $parse_uri = '/ajax/wikiparse'; } else { $parse_uri = get_instance()->uri->uri_string() . '?input_wikitext_preview_field=' . urlencode($this->name); } // Toolbar ?> <div id="<?php echo $this->id . '__toolbar'; ?> "></div><?php // Textarea parent::_Load(); // Preview if ($this->preview) { ?> <div id="<?php echo $this->id . '__preview'; ?> " class="input_wikitext_preview"<?php if ($this->value === '') { ?> style="display:none"<?php } ?> ><?php echo $this->ValueXhtml(); ?> </div><?php } // Toolbar initialisation echo js_block('mwSetupToolbar(' . js_literalise($this->id . '__toolbar') . ',' . js_literalise($this->id . '__val') . ',' . 'false' . ($this->preview ? ',[' . js_literalise($this->id . '__preview') . ',' . js_literalise($parse_uri) . ']' : '') . ');'); }
/** Tips management. */ function tips($category = null, $argument = null) { if (!CheckPermissions('office')) { return; } $permissions = array('index' => $this->permissions_model->hasUserPermission('CROSSWORD_INDEX'), 'tips_index' => $this->permissions_model->hasUserPermission('CROSSWORD_TIPS_INDEX'), 'tip_cat_add' => $this->permissions_model->hasUserPermission('CROSSWORD_TIP_CATEGORY_ADD'), 'tip_cat_view' => $this->permissions_model->hasUserPermission('CROSSWORD_TIP_CATEGORY_VIEW'), 'tip_cat_edit' => $this->permissions_model->hasUserPermission('CROSSWORD_TIP_CATEGORY_MODIFY')); if (null === $category) { // Main tip index page showing tip categories if (!CheckRolePermissions('CROSSWORD_TIPS_INDEX')) { return; } $data = array('Permissions' => &$permissions, 'Categories' => $this->crosswords_model->GetTipCategories(), 'SelfUri' => $this->uri->uri_string()); $this->main_frame->setContentSimple('crosswords/office/tips', $data); } else { $category_info = null; if (is_numeric($category)) { $category_info = $this->crosswords_model->GetTipCategories((int) $category); if (empty($category_info)) { $category_info = null; } else { $category_info = $category_info[0]; } } $edit = 'edit' === $argument; if ('add' === $category || $edit) { // Page to add or edit a category if ($edit) { if (!CheckRolePermissions('CROSSWORD_TIP_CATEGORY_MODIFY')) { return; } if (null === $category_info) { show_404(); } } else { if (!CheckRolePermissions('CROSSWORD_TIP_CATEGORY_ADD')) { return; } } // Go back to last page if (isset($_POST['tip_cat_cancel'])) { if (isset($_GET['ret'])) { redirect($_GET['ret']); } else { redirect('office/crosswords/tips'); } } $this->load->helper('input'); $form = new InputInterfaces(); $not_saving = false; if (!$edit) { $category_info = array('id' => null, 'name' => '', 'description' => ''); } else { if ($category_info['tip_count'] == 0) { $delete_interface = new InputCheckboxInterface('delete', false); $delete_confirm_interface = new InputCheckboxInterface('delete_confirm', false); $delete_interface->Validate(); $delete_confirm_interface->Validate(); if ($delete_confirm_interface->Updated() || $delete_interface->Changed()) { if ($delete_interface->Changed()) { $not_saving = true; } if ($delete_confirm_interface->Changed()) { $not_saving = true; if ($this->crosswords_model->DeleteTipCategory($category_info['id'])) { $this->messages->AddMessage('success', 'Tip category deleted'); if (isset($_GET['ret'])) { redirect($_GET['ret']); } else { redirect('office/crosswords/tips'); } } else { $this->messages->AddMessage('error', 'Tip category could not be deleted'); $form->Add('Delete tip category', $delete_interface); } } else { $this->messages->AddMessage('warning', 'Please confirm that you are sure you want to delete this tip category?'); $form->Add('Confirm deletion', $delete_confirm_interface); } } else { $form->Add('Delete tip category', $delete_interface); } } } $name_interface = new InputTextInterface('name', $category_info['name']); $name_interface->SetMaxLength(255); $name_interface->SetRequired(true); $form->Add('Name', $name_interface); $description_interface = new InputTextInterface('description', $category_info['description']); $description_interface->SetMultiline(true); $form->Add('Description', $description_interface); if (!$not_saving) { $num_errors = $form->Validate(); if (0 == $num_errors && $form->Updated()) { $values = $form->ChangedValues(); $error = false; if (count($values) == 0) { $this->messages->AddMessage('information', "You did not make any changes"); $error = true; } if (!$error) { if (!$edit) { $id = $this->crosswords_model->AddTipCategory($values); if ($id === null) { $this->messages->AddMessage('error', 'Tip category could not be added'); } else { $this->messages->AddMessage('success', 'Tip category added'); if (isset($_GET['ret'])) { redirect($_GET['ret']); } redirect('office/crosswords/tips/' . $id); } } else { $values['id'] = $category_info['id']; if (!$this->crosswords_model->UpdateTipCategory($values)) { $this->messages->AddMessage('error', 'Changes could not be saved'); } else { $this->messages->AddMessage('success', 'Changes have been saved successfully'); if (isset($_GET['ret'])) { redirect($_GET['ret']); } foreach ($values as $id => $value) { $category_info[$id] = $value; } } } } } } $data = array('Permissions' => &$permissions, 'Form' => &$form, 'Actions' => array('add' => $edit ? 'Save tip category' : 'Add tip category', 'cancel' => 'Cancel'), 'PostAction' => $this->uri->uri_string() . (isset($_GET['ret']) ? '?ret=' . urlencode($_GET['ret']) : '')); $this->main_frame->setContentSimple('crosswords/office/tip_cat_edit', $data); } else { if (!CheckRolePermissions('CROSSWORD_TIP_CATEGORY_VIEW')) { return; } if (null === $category_info) { $this->messages->AddMessage('error', 'Tip category ' . xml_escape($category) . ' does not exist'); if (isset($_GET['ret'])) { redirect($_GET['ret']); } else { redirect('office/crosswords/tips'); } } $data = array('Permissions' => &$permissions, 'Category' => $category_info, 'Tips' => new CrosswordTipsList($category_info['id'], null, true), 'PostAction' => $this->uri->uri_string()); $this->main_frame->setContentSimple('crosswords/office/tip_cat_view', $data); } } $this->main_frame->Load(); }
protected function _Validate(&$value, &$errors, &$warnings) { $ok = parent::_Validate($value, $errors, $warnings); if (!is_numeric($value)) { $errors[] = "not a number"; $ok = false; } else { $value = (int) $value; if ($this->min !== null && $value < $this->min) { $errors[] = "below the lower limit of {$this->min}"; $ok = false; } else { if ($this->max !== null && $value > $this->max) { $errors[] = "above the upper limit of {$this->max}"; $ok = false; } } } return $ok; }