/** * forgot - I forgot my password and need to reset it. Takes an email address and * sends a confirmation email with a random token to that address. * * @return void **/ function forgot() { $form = new NQuickForm('reset_password', 'post'); $form->addElement('text', 'email', 'Email Address', array('maxlength' => 32, 'style' => 'width:300px;')); $form->addElement('submit', 'reset_password', 'Reset Password'); $form->addRule('email', 'You need to enter an email address.', 'required', null, 'client'); $form->addRule('email', 'The email does not appear to be the correct format', 'email', null, 'client'); if ($form->validate()) { $vals = $form->exportValues(); if (isset($vals['email'])) { $cms_auth = NModel::factory('cms_auth'); // Set the token - then send the email. if ($result = $cms_auth->setConfirmationToken($vals['email'])) { // Send the confirmation email. $user = NController::factory('users'); $user->sendConfirmationEmail($vals['email']); } } // TODO: Put this into the template and out of here. if ($result == true) { $content = '<p><b>We have sent you a confirmation - please check your email and follow the instructions.</b></p>'; } else { $content = '<p><b>There was a problem - please <a href="javascript:history.go(-1);">click back and enter your email address again.</a></b></p>'; } $this->set(array('MAIN_CONTENT' => $content, 'forgot' => 'true')); } else { $content = $form->toHTML(); $this->set(array('MAIN_CONTENT' => $content, 'forgot' => 'true')); } $this->auto_render = false; $this->render(array('layout' => 'login')); }
/** * viewlist - Shows a list of audit trail records from the current date (by default). * Can browse around records from different dates using the form * at the top of the page. * * @return void **/ function viewlist($parameter) { include_once 'n_date.php'; include_once 'n_quickform.php'; require_once 'HTML/QuickForm/Renderer/Array.php'; $this->_auth = new NAuth(); $this->auto_render = false; // set up the search form $form = new NQuickForm('audit_search', 'get'); if ($date_params = $this->getParam('date')) { $date = $this->dateStartEnd($date_params); } else { $date = $this->dateStartEnd(); } $el =& $form->addElement('date', 'date', 'Date', array('addEmptyOption' => true, 'format' => 'F d Y', 'maxYear' => 2015)); $el->setValue($date['used']); $form->addElement('submit', null, 'Search'); $renderer = new HTML_QuickForm_Renderer_Array(true, true); $form->accept($renderer); $this->set('audit_search', $renderer->toArray()); $model =& $this->getDefaultModel(); if ($model->find(array('conditions' => 'cms_created BETWEEN ' . $model->quote($date['start']) . ' AND ' . $model->quote($date['end']), 'order_by' => 'cms_created DESC'))) { $html = ''; if ($date['month']) { $html .= "<p>Showing Monthly Results for: " . date("F, Y", strtotime($date['used'])); } while ($model->fetch()) { // Actually turn the id's into something readable. $info = $this->humanizeAuditTrailRecord($model); $this->set($info); $html .= $this->render(array('action' => 'audit_trail_record', 'return' => true)); } $this->set('audit_trail', $html); $this->set('result_count', $model->numRows()); } else { $this->set('result_count', 'no'); $this->set('audit_trail', '<p>There were no results found for the specified date.</p>'); } // Exposes an RSS feed link to Admin or higher users. if (defined('RSS_AUDIT_TRAIL') && RSS_AUDIT_TRAIL) { NDebug::debug('We are checking to see if we can display the RSS feed.', N_DEBUGTYPE_INFO); $this->checkRSSFeed(); } $this->set('date', $date['used']); $this->loadSubnav($parameter); $this->render(array('layout' => 'default')); }
function viewlist() { $this->auto_render = false; include_once 'n_quickform.php'; $model =& $this->getDefaultModel(); $pk = $model->primaryKey(); $setting_forms = array(); $user_settings = $GLOBALS['USER_SETTINGS']; foreach ($user_settings as $setting => $default) { $model->reset(); $model->user_id = (int) $this->_auth->currentUserId(); $model->setting = $setting; $form = new NQuickForm('setting_' . $setting); $form->addElement('header', null, $model->settingToText($setting)); $description = $this->getSettingDescription($setting); if (!$description) { $description = 'Setting'; } $form->addElement('hidden', 'setting', $setting); $checkbox =& $form->addElement('checkbox', 'value', $description, null, array('id' => 'qf_' . $model->setting)); if ($model->find(null, true)) { // set the form action to edit $form->updateAttributes(array('action' => '/' . APP_DIR . '/' . $this->name . '/edit/' . $model->{$pk})); $form->addElement('hidden', $pk, $model->{$pk}); // check the box according to the value $checkbox->setChecked((bool) $model->value); } else { $form->updateAttributes(array('action' => '/' . APP_DIR . '/' . $this->name . '/create')); $checkbox->setChecked((bool) $default); } $form->addElement('hidden', '_referer', urlencode(NServer::env('REQUEST_URI'))); $form->addElement('submit', '__submit__', 'Submit'); $form->addRule('setting', null, 'required'); $setting_forms[] =& $form; } $this->set('settings', $setting_forms); $this->render(array('layout' => 'default')); }
function addExistingContent($parameter) { $page_model =& $this->loadModel('page'); $page_model->get($parameter); $template_container_id = isset($this->params['template_container_id']) ? $this->params['template_container_id'] : false; $asset = isset($this->params['asset']) ? $this->params['asset'] : false; // instantiate form include_once 'n_quickform.php'; $form = new NQuickForm(); $values = $form->getSubmitValues(); $form->addElement('header', null, 'Add "' . Inflector::humanize($asset) . '" content to the "' . $page_model->title . '" page'); $asset_controller =& NController::factory($asset); $asset_model =& NModel::factory($asset); $pk = $asset_model->primaryKey(); $records = array(); if ($asset_model->find()) { while ($asset_model->fetch()) { $records[$asset_model->{$pk}] = $asset_model->cms_headline; } } unset($asset_model); // add asset select $options = defined('SITE_WORKFLOW') && SITE_WORKFLOW ? array() : array('size' => 10, 'multiple' => 'multiple'); $form->addElement('select', 'asset_id', Inflector::humanize($asset), $records, $options); // hidden fields $form->addElement('hidden', 'asset', $asset); $form->addElement('hidden', 'template_container_id', $template_container_id); if (isset($this->params['_referer'])) { $form->addElement('hidden', '_referer', urlencode($this->params['_referer'])); } // finish up $form->addElement('submit', '__submit__', 'Add Content'); // rules defined('SITE_WORKFLOW') && SITE_WORKFLOW ? $form->addRule('asset_id', 'You must select a record.', 'required') : $form->addGroupRule('asset_id', 'You must select a record.', 'required'); $form->addRule('asset', '', 'required'); $form->addRule('template_container_id', '', 'required'); // check for workflow $user_rights = 0; if (SITE_WORKFLOW) { // get the users rights and bit compare them below $workflow =& NController::factory('workflow'); $user_rights = $workflow->getWorkflowUserRights($page_model); if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) { if (!($user_rights & WORKFLOW_RIGHT_EDIT)) { // they don't belong here - go to the dashboard header('Location:/' . APP_DIR . '/dashboard'); } else { if ($user_rights & WORKFLOW_RIGHT_EDIT) { $form->insertElementBefore(NQuickForm::createElement('submit', '__submit_workflow__', 'Start Workflow'), '__submit__'); $form->removeElement('__submit__'); } } } unset($workflow); } $form->addElement('header', null, 'Make it timed content?'); $timed_options = array('format' => 'Y-m-d H:i', 'minYear' => date('Y'), 'maxYear' => date('Y') + 4, 'addEmptyOption' => true); $form->addElement('date', 'timed_start', 'Timed Start', $timed_options); $form->addElement('date', 'timed_end', 'Timed End', $timed_options); if (!$user_rights) { $form->addElement('submit', '__submit_timed__', 'Add Scheduled Content'); } else { $form->addElement('submit', '__submit_workflow__', 'Start Workflow with Scheduled Content'); } if ($form->validate()) { $values = $form->exportValues(); $model =& $this->loadModel($this->name); $workflow_active = false; if (SITE_WORKFLOW) { $workflow =& NController::factory('workflow'); // check if this content is on any other page. // if it is, if either pages are part of a workflow group, we need to copy the content (go to addnewcontent with notice) // if neither do, then go ahead $asset_model =& $asset_controller->loadModel($asset_controller->name); $asset_model->get($values['asset_id']); $other_page =& $this->getContentPage($asset_controller); if ($other_page) { $owned_content = false; if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) { $owned_content = true; } else { if ($workflow_group_model =& $workflow->getWorkflowGroup($other_page)) { $owned_content = true; } } // if the content is already connected somewhere and one of the pages belongs to a workflow_group, then addNewContent with preloaded content if ($owned_content) { if (isset($values['__submit__'])) { unset($values['__submit__']); } if (isset($values['__submit_workflow__'])) { unset($values['__submit_workflow__']); } $this->redirectTo('copy_existing_content', $parameter, $values); exit; } } if (isset($values['__submit_workflow__']) && $values['__submit_workflow__']) { $workflow =& NController::factory('workflow'); if ($workflow_group_model = $workflow->getWorkflowGroup($page_model)) { $workflow_active = true; } } } $model->page_id = $parameter; if (SITE_WORKFLOW && isset($values['__submit_workflow__']) && $values['__submit_workflow__']) { $model->cms_workflow = 1; } $model->page_template_container_id = $values['template_container_id']; $model->content_asset = $values['asset']; // set the timed values $timed_start = null; $timed_end = null; include_once 'n_date.php'; if (isset($values['timed_start'])) { $timed_start = NDate::arrayToDate($values['timed_start']); $timed_start = NDate::convertTimeToUTC($timed_start); unset($values['timed_start']); } if (isset($values['timed_end'])) { $timed_end = NDate::arrayToDate($values['timed_end']); $timed_end = NDate::convertTimeToUTC($timed_end); unset($values['timed_end']); } if (!$workflow_active) { $table = $model->table(); $def = $table['timed_start']; if (NDate::validDateTime($timed_start, $def)) { $model->timed_start = $timed_start; } else { $model->timed_start = N_DAO_NOTNULL & $def ? $timed_start : 'null'; } $def = $table['timed_end']; if (NDate::validDateTime($timed_end, $def)) { $model->timed_end = $timed_end; } else { $model->timed_end = N_DAO_NOTNULL & $def ? $timed_end : 'null'; } } $model->cms_created = $model->now(); $model->cms_modified = $model->now(); $model->cms_modified_by_user = $this->_auth->currentUserID(); if (!is_array($values['asset_id'])) { $values['asset_id'] = array($values['asset_id']); } foreach ($values['asset_id'] as $asset_id) { $model->content_asset_id = $asset_id; $model->insert(); if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) { // audit trail $audit_trail =& NController::factory('audit_trail'); $audit_trail->insert(array('asset' => $asset_controller->name, 'asset_id' => $asset_id, 'action_taken' => AUDIT_ACTION_CONTENT_ADDEXISTING, 'page_content_id' => $model->{$model->primaryKey()}, 'page_id' => $model->page_id)); unset($audit_trail); } } if ($workflow_active) { $asset_controller =& NController::factory($values['asset']); $asset_controller->_auth = new NAuth(); $asset_model =& $asset_controller->getDefaultModel(); $asset_model->get($values['asset_id'][0]); $workflow_values = array(); $workflow_values['page_content_id'] = $model->{$model->primaryKey()}; $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()}; // add timed content $workflow_values['timed_start'] = $timed_start; $workflow_values['timed_end'] = $timed_end; $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_ADDEXISTING, $asset_controller); } // delete the page cache $page =& NController::singleton('page'); $page->deletePageCache($model->page_id); unset($page); // set up the referer if (isset($this->params['_referer']) && $this->params['_referer']) { $referer = urldecode($this->params['_referer']); } else { include_once 'view/helpers/url_helper.php'; $referer = urlHelper::urlFor($this, array('controller' => 'page', 'action' => 'surftoedit', 'id' => $parameter)); } header('Location:' . $referer); exit; } $this->auto_render = false; $this->page_title = 'Add Existing Content to "' . $page_model->title . '"'; $this->set(array('title' => 'Select Content', 'form' => $form->toHTML())); $this->render(array('action' => 'form', 'layout' => 'plain')); unset($page_model); }