function delete($parameter) { if (empty($parameter)) { $this->redirectTo(array('dashboard')); } // load the model layer with info $model =& NModel::factory($this->name); if (!$model) { $this->redirectTo(array('dashboard')); } if ($model->get($parameter)) { // if the content record is flagged with cms_draft=1, then the content has never been published and should be deleted altogether $content_model =& NModel::factory($model->asset); if ($content_model && $content_model->get($model->asset_id) && $content_model->cms_draft == 1) { $content_model->delete(); } unset($content_model); if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) { // audit trail before delete so we don't lose the values $audit_trail =& NController::factory('audit_trail'); $audit_trail->insert(array('asset' => $this->name, 'asset_id' => $model->{$model->primaryKey()}, 'action_taken' => AUDIT_ACTION_DRAFT_DELETE)); unset($audit_trail); } $model->delete(); if (isset($this->params['_referer']) && $this->params['_referer']) { header('Location:' . urldecode($this->params['_referer'])); exit; } $this->postProcessForm($model->toArray()); $this->flash->set('notice', 'Draft deleted.'); } $this->redirectTo(array('dashboard')); }
function displayEditStatus($items) { $time_now = time(); foreach ($items as $item) { $time_diff = $time_now - $item['timestamp']; // Grab information about the person editing. $user_info = NModel::factory('cms_auth'); $user_info->id = $item['user_id']; if ($user_info->find()) { while ($user_info->fetch()) { $name = $user_info->real_name; $email = $user_info->email; } } unset($cms_auth); // Check to see if you're the one editing. $auth = new NAuth(); $current_user_id = $auth->currentUserID(); unset($auth); // Output the item. if ($current_user_id == $item['user_id']) { print '<div id="actiontrack">You have been editing this record for ' . $time_diff . ' seconds.</div>'; } else { print '<div id="actiontrack"><a href="mailto:' . $email . '">' . $name . '</a> was editing this item ' . $time_diff . ' seconds ago.</div>'; } } }
/** * insert_audit_trail - This is only for timed_remove so that we don't * lose the audit_trail. * Refactor: Duplication of audit_trail_controller->insert(); * * @param array Required params - asset, asset_id, action_taken * @return void **/ function insert_audit_trail($params = array()) { if (empty($params)) { return false; } $required_params = array('asset', 'asset_id', 'action_taken'); foreach ($required_params as $param) { if (!isset($params[$param])) { return false; } } $model =& NModel::factory($this->name); // apply fields in the model $fields = $model->fields(); foreach ($fields as $field) { $model->{$field} = isset($params[$field]) ? $params[$field] : null; } $model->user_id = $this->website_user_id; $model->ip = NServer::env('REMOTE_ADDR'); if (in_array('cms_created', $fields)) { $model->cms_created = $model->now(); } if (in_array('cms_modified', $fields)) { $model->cms_modified = $model->now(); } // set the user id if it's applicable and available if (in_array('cms_modified_by_user', $fields)) { $model->cms_modified_by_user = $this->website_user_id; } $model->insert(); }
function function_assign_home_children($params, &$view) { $page_model = NModel::factory('page'); $conditions = "parent_id = 1 AND visible = 1 AND active = 1"; $page_model->find(array("conditions" => $conditions)); $view->assign('home_children', $page_model->fetchAll(true)); }
function getPTIFromId($id) { $model =& NModel::factory($this->name); $model->id = $id; if ($model->find()) { while ($model->fetch()) { $result = $model->toArray(); } $page_template_id = $result['page_template_id']; } unset($model); return $page_template_id; }
public static function forGroup($group) { if (!$group) { throw new Exception("Group not specified", 1); } $model = NModel::factory('password'); $conditions = array('conditions' => "cms_headline = '{$group}'"); if ($model->find($conditions)) { $model->fetch(); } else { throw new Exception("Invalid password group: {$group}", 1); } return $model; }
/** * uniqueUsername - Make sure that the username is unique. * * @param string The username to check. * @return boolean **/ function uniqueUsername($value) { $id = $this->{$this->primaryKey()}; $model =& NModel::factory($this->__table); if ($model) { $conditions = $id ? $model->primaryKey() . '!=' . $id : ''; $model->username = $value; if ($model->find(array('conditions' => $conditions))) { unset($model); return false; } } unset($model); return true; }
function searchFieldListSelect($params) { $asset = $params['asset'] ? $params['asset'] : null; $searched_field = $params['searched_field'] ? $params['searched_field'] : null; if (isset($searched_field)) { $searched_field = str_replace(" ", "_", strtolower($searched_field)); } $model = NModel::factory($asset); $fields = $model->fields(); // Remove a bunch of fields if you're not an admin - makes it a little bit simpler. $auth = new NAuth(); $current_user_level = $auth->getAuthData('user_level'); unset($auth); // Preload for the search_field default. $acon = NController::factory('asset'); $select = 'Search Field: <select name="search_field">'; foreach ($fields as $field) { if ($current_user_level < N_USER_ADMIN) { if (in_array($field, $this->admin_only_fields)) { continue; } } $select .= '<option value="' . $field . '"'; if (isset($searched_field) && $searched_field == $field) { $select .= ' selected="selected"'; } elseif (isset($model->search_field) && $field == $model->search_field && !$searched_field) { $select .= ' selected="selected"'; } elseif (!isset($model->search_field) && $field == $acon->search_field && !$searched_field) { $select .= ' selected="selected"'; } $select .= '>' . ucwords(str_replace('_', ' ', $field)) . '</option>'; } $select .= '</select>'; unset($model); unset($acon); print $select; }
function afterDelete($page_id) { // After a page is deleted, make sure to remove all linked // content from the page_content table. Cleans things up and // helps with some possible workflow trauma. $page_content = NModel::factory('page_content'); $page_content->deleteOrphanedPageContent($page_id); // Delete Smarty Cache $this->deleteSmartyCache(); }
/** * getFilePath - Returns the full path to the filename * referenced in model/field/asset_id * * @return string The filename from the db plus DOCUMENT_ROOT. **/ function getFilePath() { if (is_numeric($this->asset_id)) { $object = NModel::factory($this->model); $object->id = $this->asset_id; if ($object->find()) { while ($object->fetch()) { $filename = $object->{$this->field}; } return DOCUMENT_ROOT . $filename; } } else { return false; } }
function getWorkflow($page_content_id, $workflow_group_id, &$asset_controller, $completed = 0) { if (!$asset_controller || !($asset_model =& $asset_controller->getDefaultModel())) { return false; } $pk = $asset_model->primaryKey(); $model =& NModel::factory($this->name); $model->page_content_id = $page_content_id; $model->workflow_group_id = $workflow_group_id; $model->asset = $asset_controller->name; $model->asset_id = $asset_model->{$pk}; $model->completed = (int) $completed; if ($model->find(array('order_by' => 'id DESC'), true)) { return $model; } unset($model); return false; }
function social($params) { extract($params); $page_model = NModel::factory('page'); // Get the head item $conditions = "parent_id = {$head}"; $page_model->find(array("conditions" => $conditions)); $this->set('pages', $page_model->fetchAll(true)); return $this->render(array('action' => 'social', 'return' => true)); }
function getPTCIFromId($id) { $model =& NModel::factory($this->name); $model->id = $id; if ($model->find()) { while ($model->fetch()) { $result = $model->toArray(); } $page_template_container_id = $result['page_template_container_id']; // Set the asset name for postGenerateForm. $this->passed_asset = $result['asset']; } unset($model); return $page_template_container_id; }
function postProcessForm(&$values) { $model =& $this->getDefaultModel(); $pk = $model->primaryKey(); // fix the paths for navigation // if (on insert or if changed path on update) $this->fixPaths($model->{$pk}); // move all the old content to the current template // into matching template containers if (isset($values['mv_content'])) { $page_content =& NController::singleton('page_content'); $page_content->changeTemplate($model->{$pk}, $model->page_template_id); } // delete general caches include_once 'n_cache.php'; NCache::removeMenu(); NCache::removeTreeAsSelect(); NCache::removeJavascript($model->{$pk}); // REMOVE PAGE CACHE $this->deletePageCache($model->{$pk}); // REMOVE PARENT PAGE CACHE (for child links, etc); if ($this->action == 'create') { // load a new one $new_model =& NModel::factory($this->name); $parent_id = $new_model->getParent($model->{$pk}); unset($new_model); } else { // user the existing model to find the parent $parent_id = $model->getParent($model->{$pk}); } $this->deletePageCache($parent_id); // remove the site admin cache $site_admin =& NController::singleton('site_admin'); $site_admin->deleteCache(); unset($site_admin); if ($this->action == 'delete') { $this->flash->set('notice', 'Your page has been deleted.'); } else { $this->flash->set('notice', 'Your page has been saved.'); } parent::postProcessForm($values); }
function deleteCache() { $auth_model =& NModel::factory('cms_auth'); if ($auth_model->find()) { $pk = $auth_model->primaryKey(); while ($auth_model->fetch()) { // remove the site admin cache $this->view_cache_name = 'nterchange_site_admin_' . $auth_model->{$pk}; $view =& NView::singleton($this); $view->clearLayoutCache('default'); } } unset($auth_model); unset($view); }
/** * Loads a reference to the model that is passed into the $this->models * array and returns it * * @see NModel:factory(); * @return object */ function &loadModel($model) { if (!isset($this->models[$model])) { $this->models[$model] =& NModel::factory($model); if ($this->models[$model] == false) { unset($this->models[$model]); $ret = false; return $ret; } } return $this->models[$model]; }
function mediaBrowse() { $this->set('ckeditorfuncnum', $_GET['CKEditorFuncNum']); require_once 'n_quickform.php'; $this->auto_render = false; // Media Element Browser $form = new NQuickform(); $model =& NModel::factory('media_element'); $modelIndex = array(); $model->find(); $media_elements = $model->fetchAll(true); foreach ($media_elements as $i) { $modelIndex[$i['media_file']] = $i['cms_headline']; } $form->addElement('select', 'mediaelement', "Media Element", $modelIndex, array("id" => "mediaelement")); $form->addElement('button', 'mediaelementsubmit', "Submit", array("onclick" => "javascript: me_callback()")); $page_controller =& NController::factory('page'); $pageTree = $page_controller->getTreeAsSelect('pages', "Pages"); $form->addElement($pageTree); $form->addElement('button', 'pagessubmit', "Submit", array("onclick" => "javascript: pg_callback()")); $this->set('title', 'Choose file or page to link to:'); $this->set('form', $form->toHtml()); $this->render(array('layout' => 'simple')); }
/** * checkRSSFeed - Checks the level of the user and exposes a link to an audit trail RSS feed * to that user if they're an admin level or higher. * * @return void **/ function checkRSSFeed() { // Check the user level - this only shows up for admins or higher. $auth = new NAuth(); $current_user_level = $auth->getAuthData('user_level'); $user_id = $auth->currentUserID(); if ($current_user_level >= N_USER_ADMIN) { // Get their feed token if they have it. $cms_user = NModel::factory('cms_auth'); $feed_token = $cms_user->getFeedToken($user_id); unset($cms_user); // If they don't have one, we should help them to generate it. if (!isset($feed_token)) { $rss = '<p><a href="/nterchange/rss/generate_feed_token?redirect=' . urlencode('/nterchange/audit_trail/viewlist') . '">Click here to generate a private RSS feed</a></p>'; } else { $rss = '<p><a href="/nterchange/rss/audit_trail?token=' . $feed_token . '">Private RSS Feed of Audit Trail Activity</a> - <a href="/nterchange/audit_trail/generate_feed_token">Regenerate Token</a></p>'; } // Then show the link so that they can put it into their feed reader. $this->set('rss_feed', $rss); } unset($auth); }
/** * getCurrentVersion - Get the current version of the $asset referenced by $asset_id * * @param string The name of the asset. * @param int The id of that asset. * @return array All the content in that asset. **/ function getCurrentVersion($asset, $asset_id) { $asset_object = NModel::factory($asset); $asset_object->id = $asset_id; if ($asset_object->find()) { while ($asset_object->fetch()) { $arr = $asset_object->toArray(); return $arr; } } else { return false; } }
function export($model_name) { if (isset($model_name)) { $model = NModel::factory($model_name); // Foreign Key Lookup Support if (isset($model->excel_export)) { $model_foreign_keys = $model->excel_export; // Default standard foreign keys get added and merged here. $foreign_keys = array_merge($this->default_foreign_keys, $model_foreign_keys); } else { $foreign_keys = $this->default_foreign_keys; } // Field Inclusion and Exclusion Support if (isset($model->excel_exclude_fields)) { $model_excel_inclusions = $model->excel_exclude_fields; $field_exclusions = array_merge($this->default_field_exclusions, $model_excel_inclusions); } else { $field_exclusions = $this->default_field_exclusions; } // If $_GET['search'] is set, only export those items. $search = isset($_GET['search']) ? $_GET['search'] : null; $search_field = isset($_GET['search_field']) ? $_GET['search_field'] : null; if (isset($search) && $search != null) { if (!$search_field && $search_field != null) { $acon = NController::factory('asset'); $search_field = isset($model->search_field) ? $model->search_field : $acon->search_field; unset($acon); } } $options = $search ? array('conditions' => "{$search_field} LIKE '%{$search}%'") : array(); // Can set options in the model about items exported to the Excel. // Only export items that meet a certain criteria - not everything in the list. // For example: $this->viewlist_options = array('conditions'=>"cms_modified_by_user = '******'"); if (isset($model->viewlist_options)) { foreach ($model->viewlist_options as $key => $val) { if (isset($options[$key])) { $options[$key] .= ' AND ' . $val; } else { $options[$key] = "{$val}"; } } } if ($model->find($options)) { $fields = $model->fields(); // Add additional custom fields here from the model file. if (isset($model->excel_extra_fields)) { foreach ($model->excel_extra_fields as $key => $value) { $fields[] = $key; } } require_once 'Spreadsheet/Excel/Writer.php'; // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); $worksheet =& $workbook->addWorksheet(ucwords(str_replace('_', ' ', $model_name))); $worksheet->setColumn(2, 4, 20); $worksheet->setColumn(7, 7, 15); $worksheet->setColumn(10, 28, 20); // Make the title line look a little different $title =& $workbook->addFormat(); $title->setBold(); $title->setAlign('center'); $title->setBottom(2); // Let's add the field names to the title line. // Leave out a few. $x = 0; $worksheet->setRow(0, 18.75); foreach ($fields as $field) { $exclude_this = array_key_exists($field, $field_exclusions); if ($exclude_this && $field_exclusions[$field] == true) { // do nothing } else { $worksheet->write(0, $x, ucwords(str_replace('_', ' ', $field)), $title); $x++; } } // Now here comes the data. $y = 1; while ($model->fetch()) { $item = $model->toArray(); // For reference while we're working with things. $original_item = array(); $original_item = $item; $x = 0; $worksheet->setRow($y, 18.75); foreach ($fields as $field) { $exclude_this = array_key_exists($field, $field_exclusions); if ($exclude_this && $field_exclusions[$field] == true) { // do nothing } else { // Look for foreign keys and replace if assigned. foreach ($foreign_keys as $foreign_key => $foreign_key_value) { if ($field == $foreign_key) { $fk_model_name = $foreign_key_value[0]; $fk_model_headline = $foreign_key_value[1]; $fk_model = NModel::factory($fk_model_name); if ($fk_model && $fk_model->get($item[$field])) { $item[$field] = $fk_model->{$fk_model_headline}; } unset($fk_model); } } //Look for bitmask fields and replace with string value instead of numeric total if (is_array($model->bitmask_fields) && count($model->bitmask_fields)) { $bitmask_keys = array_keys($model->bitmask_fields); if (in_array($field, $bitmask_keys)) { $bitmask_total = $item[$field]; $value_str = ''; $i = 0; foreach ($model->bitmask_fields[$field] as $bit => $val) { if ($bit & $bitmask_total) { if ($i > 0) { $value_str .= ', '; } $value_str .= $val; $i++; } } $item[$field] = $value_str; } } // Any extra fields get dealt with here. if (isset($model->excel_extra_fields)) { foreach ($model->excel_extra_fields as $key => $value) { if ($field == $key) { $extra_name = $value[0]; $extra_attribute = $value[1]; $extra_key = $value[2]; $extra_info = NModel::factory($extra_name); if (method_exists($extra_info, $extra_attribute)) { $item[$field] = $extra_info->{$extra_attribute}($original_item["{$extra_key}"]); } else { $extra_info->get($original_item["{$extra_key}"]); $item[$field] = $extra_info->{$extra_attribute}; } unset($extra_info); } } } // If it's an uploaded file, put the address in the conf.php before it so that it // turns into a link in Excel. if (eregi(UPLOAD_DIR, $item[$field])) { $item[$field] = PUBLIC_SITE . ereg_replace("^/", "", $item[$field]); } $worksheet->write($y, $x, $this->convert_characters($item[$field])); $x++; } } $y++; unset($original_item); unset($item); } // sending HTTP headers $xls_filename = $model_name . '_entries.xls'; $workbook->send($xls_filename); $workbook->close(); } } }
</td></tr> <tr><td>APP_DIR</td><td><?php echo APP_DIR; ?> </td></tr> <tr><td>BASE_DIR</td><td><?php echo BASE_DIR; ?> </td></tr> <tr> <?php $db = NDB::connect(); ?> <th colspan="2">Database</th> </tr> <tr> <?php $m = NModel::factory('cms_auth'); $user_count = $m->find(); ?> <td># of users</td><td><?php echo $user_count; ?> </td> </tr> </table> </body> </html>
function HTML_QuickForm_fckeditor($elementName = null, $elementLabel = null, $attributes = null, $options = null) { include_once BASE_DIR . '/nterchange/javascripts/fckeditor/fckeditor.php'; $this->_editor = new FCKEditor($elementName); $settings_model =& NModel::factory('cms_settings'); $editor_set = $settings_model->getSetting(SETTINGS_EDITOR); unset($settings_model); if ($editor_set == false || !$this->_editor->IsCompatible()) { HTML_QuickForm_textarea::HTML_QuickForm_textarea($elementName, $elementLabel, $attributes); // if the browser isn't compatible, then remove _editor parameter and set up as a textarea unset($this->_editor); $this->updateAttributes(array('rows' => 25, 'cols' => 60, 'style' => 'width:470px;height:500px;')); } else { HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_type = 'fckeditor'; $this->_persistantFreeze = true; // set base options and paths $this->_editor->BasePath = '/nterchange/javascripts/fckeditor/'; $this->_editor->Width = '470px'; $this->_editor->Height = '500px'; if (file_exists(DOCUMENT_ROOT . '/includes/fckstyles.xml')) { $this->_editor_config['StylesXmlPath'] = '/includes/fckstyles.xml'; } if (file_exists(DOCUMENT_ROOT . '/includes/fcktemplates.xml')) { $this->_editor_config['TemplatesXmlPath'] = '/includes/fcktemplates.xml'; } // overwrite any set $_editor_options with the passed $options, only allowing the ones that already exist if (is_array($options)) { foreach ($options as $option => $val) { if (in_array($option, array_keys($this->_editor_config))) { $this->_editor_config[$option] = $val; } } } // load any $_editor_options that are not null into the $_editor->Config array foreach ($this->_editor_config as $option => $val) { if (!is_null($val)) { $this->_editor->Config[$option] = $val; } } // point at nterchange custom configuration file if (file_exists(DOCUMENT_ROOT . '/javascripts/fckconfig.js')) { $this->_editor->Config['CustomConfigurationsPath'] = '/javascripts/fckconfig.js?' . filemtime(DOCUMENT_ROOT . '/javascripts/fckconfig.js'); } else { $this->_editor->Config['CustomConfigurationsPath'] = $this->_editor->BasePath . 'n_config.js?' . filemtime(BASE_DIR . '/nterchange/javascripts/fckeditor/n_config.js'); } // set the toolbar to our configured toolbar $this->_editor->ToolbarSet = 'nonfiction'; } }
/** * doesAssetDatabaseTableExist - Check for the existance of an asset's database table. * * @param string The name of the asset * @return boolean Does it exist or not? **/ function doesAssetDatabaseTableExist($asset) { $model =& NModel::factory($asset); if ($model) { if ($model->_fields) { return true; } else { return false; } } else { return false; } }
function loadSidebar($parameter) { $this->set('SIDEBAR_TITLE', $this->page_title . ' Info'); $page_model =& NModel::singleton('page'); $page_content_model =& NModel::factory('page_content'); $page_content_model->content_asset = $this->name; $page_content_model->content_asset_id = $parameter; $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_edit_status', 'return' => true))); if ($page_content_model->find()) { $pages = array(); while ($page_content_model->fetch()) { $page_model->reset(); if ($page_model->get($page_content_model->page_id)) { $pages[] = $page_model->toArray(); } } $page_model->reset(); unset($page_model); $this->set('pages', $pages); $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_page_content', 'return' => true))); } unset($page_content_model); if ($this->versioning) { $user_model = $this->loadModel('cms_auth'); $model = $this->getDefaultModel(); $model = clone $model; if (!$model->{$model->primaryKey()}) { $model->get($parameter); $this->convertDateTimesToClient($model); } $model_data = $model->toArray(); if ($user_model->get($model_data['cms_modified_by_user'])) { $model_data['user'] = $user_model->toArray(); } $this->set($model_data); $user_model->reset(); $version_model = $this->loadModel('cms_nterchange_versions'); $user_model = $this->loadModel('cms_auth'); $version_model->asset = $this->name; $version_model->asset_id = $parameter; if ($version_model->find(array('order_by' => 'cms_modified DESC'))) { $versions = array(); while ($version_model->fetch()) { $version = $version_model->toArray(); if ($version_data = @unserialize($version['version'])) { if ($user_model->get($version_data['cms_modified_by_user'])) { $version['user'] = $user_model->toArray(); } $user_model->reset(); $versions[] = $version; } } $this->set('versions', $versions); } $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'sidebar_versions', 'return' => true))); unset($version_model); } }
/** * sendConfirmationEmail - Sends a confirmation email for a password reset. * * @param string The email address to send the email to. * @return void **/ function sendConfirmationEmail($email) { $cms_auth = NModel::factory('cms_auth'); if ($confirmation_token = $cms_auth->getConfirmationToken($email)) { $this->set('confirmation_token', $confirmation_token); $this->set('ip', $_SERVER['REMOTE_ADDR']); $this->set('public_site', PUBLIC_SITE); // set up and send the email $email_message = $this->render(array('action' => 'confirmation_email', 'return' => true)); $email_from = 'website@' . $_SERVER['SERVER_NAME']; $email_to = $email; $email_subject = SITE_NAME . ' - Confirm Password Reset'; mail($email_to, $email_subject, $email_message); } }
function export($model_name) { if (isset($model_name)) { $model = NModel::factory($model_name); // Foreign Key Lookup Support if (isset($model->excel_export)) { $model_foreign_keys = $model->excel_export; // Default standard foreign keys get added and merged here. $foreign_keys = array_merge($this->default_foreign_keys, $model_foreign_keys); } else { $foreign_keys = $this->default_foreign_keys; } // Field Inclusion and Exclusion Support if (isset($model->excel_exclude_fields)) { $model_excel_inclusions = $model->excel_exclude_fields; $field_exclusions = array_merge($this->default_field_exclusions, $model_excel_inclusions); } else { $field_exclusions = $this->default_field_exclusions; } // If $_GET['search'] is set, only export those items. $search = isset($_GET['search']) ? $_GET['search'] : null; $search_field = isset($_GET['search_field']) ? $_GET['search_field'] : null; if (isset($search) && $search != null) { if (!$search_field && $search_field != null) { $acon = NController::factory('asset'); $search_field = isset($model->search_field) ? $model->search_field : $acon->search_field; unset($acon); } } $options = $search ? array('conditions' => "{$search_field} LIKE '%{$search}%'") : array(); // Can set options in the model about items exported to the Excel. // Only export items that meet a certain criteria - not everything in the list. // For example: $this->viewlist_options = array('conditions'=>"cms_modified_by_user = '******'"); if (isset($model->viewlist_options)) { foreach ($model->viewlist_options as $key => $val) { if (isset($options[$key])) { $options[$key] .= ' AND ' . $val; } else { $options[$key] = "{$val}"; } } } if ($model->find($options)) { $fields = $model->fields(); // Add additional custom fields here from the model file. if (isset($model->excel_extra_fields)) { foreach ($model->excel_extra_fields as $key => $value) { $fields[] = $key; } } // Creating a workbook $filename = $_SERVER['DOCUMENT_ROOT'] . UPLOAD_DIR . '/' . rand(1, 1000) . '-file.csv'; $fp = fopen($filename, 'w'); // Creating a workbook and sending it directly out to a browser. //$fp = fopen('php://output', 'w'); // Let's add the field names to the title line. // Leave out a few. $x = 0; foreach ($fields as $field) { $exclude_this = array_key_exists($field, $field_exclusions); if ($exclude_this && $field_exclusions[$field] == true) { // do nothing } else { $good_fields[] = $field; } } //$field_string = implode(',', $good_fields); fputcsv($fp, $good_fields); // Now here comes the data. $y = 1; while ($model->fetch()) { $data_fields = array(); $item = $model->toArray(); // For reference while we're working with things. $original_item = array(); $original_item = $item; $x = 0; foreach ($fields as $field) { $exclude_this = array_key_exists($field, $field_exclusions); if ($exclude_this && $field_exclusions[$field] == true) { // do nothing } else { // Look for foreign keys and replace if assigned. foreach ($foreign_keys as $foreign_key => $foreign_key_value) { if ($field == $foreign_key) { $fk_model_name = $foreign_key_value[0]; $fk_model_headline = $foreign_key_value[1]; $fk_model = NModel::factory($fk_model_name); if ($fk_model && $fk_model->get($item[$field])) { $item[$field] = $fk_model->{$fk_model_headline}; } unset($fk_model); } } //Look for bitmask fields and replace with string value instead of numeric total if (is_array($model->bitmask_fields) && count($model->bitmask_fields)) { $bitmask_keys = array_keys($model->bitmask_fields); if (in_array($field, $bitmask_keys)) { $bitmask_total = $item[$field]; $value_str = ''; $i = 0; foreach ($model->bitmask_fields[$field] as $bit => $val) { if ($bit & $bitmask_total) { if ($i > 0) { $value_str .= ', '; } $value_str .= $val; $i++; } } $item[$field] = $value_str; } } // Any extra fields get dealt with here. if (isset($model->excel_extra_fields)) { foreach ($model->excel_extra_fields as $key => $value) { if ($field == $key) { $extra_name = $value[0]; $extra_attribute = $value[1]; $extra_key = $value[2]; $extra_info = NModel::factory($extra_name); if (method_exists($extra_info, $extra_attribute)) { $item[$field] = $extra_info->{$extra_attribute}($original_item["{$extra_key}"]); } else { $extra_info->get($original_item["{$extra_key}"]); $item[$field] = $extra_info->{$extra_attribute}; } unset($extra_info); } } } // If it's an uploaded file, put the address in the conf.php before it so that it // turns into a link in Excel. if (eregi(UPLOAD_DIR, $item[$field])) { $item[$field] = PUBLIC_SITE . ereg_replace("^/", "", $item[$field]); } $fixed_item = $this->convert_characters($item[$field]); $data_fields[] = $fixed_item; } } //$data_string = implode(',', $data_fields); fputcsv($fp, $data_fields); unset($original_item); unset($item); unset($data_fields); } // Close the file. fclose($fp); $download = new NDownload(); $download->serveFile($filename); unlink($filename); } } }
/** * auditTrail - Create an RSS feed of audit trail records. * Shows $this->records many records. * * @return void **/ function auditTrail() { if (defined('RSS_AUDIT_TRAIL') && RSS_AUDIT_TRAIL) { $this->auto_render = false; $count = 0; $token = $this->getToken(); // It's got to be 32 characters - this keeps people from trying token= if ($length = strlen($token) < 32) { die; } if ($allowed = $this->checkToken($token)) { // Grab the last 50 results $audit_trail = NModel::factory('cms_audit_trail'); $options['order_by'] = 'cms_created DESC'; if ($audit_trail->find($options)) { while ($audit_trail->fetch()) { $audit_trail_controller = NController::factory('audit_trail'); $record = $audit_trail_controller->humanizeAuditTrailRecord($audit_trail); //varDump($record); $records[] = $record; $count++; if ($count >= $this->records) { break; } } } $this->set('records', $records); $this->render(array('action' => 'audit_trail')); } else { print "Unauthorized access"; } } }
function &getLink($field, $model) { $model =& NModel::factory($model); if (isset($this->{$field}) && $model && $model->get($this->{$field})) { return $model; } unset($model); $ret = false; return $ret; }
function checkAssetContainerUsage($asset, $container_id) { $count = 0; $model =& NModel::factory($this->name); $model->content_asset = $asset; $model->page_template_container_id = $container_id; if ($model->find()) { while ($model->fetch()) { $count++; } } unset($model); return $count; }
function index($parameter) { $this->auto_render = false; $sidebar_content = $this->render(array('action' => 'description', 'return' => true)); if (SITE_DRAFTS) { $draft_model =& NModel::factory('cms_drafts'); if ($draft_model) { $draft_model->cms_modified_by_user = $this->_auth->currentUserId(); if ($draft_model->find()) { while ($draft_model->fetch()) { $asset_ctrl =& NController::factory($draft_model->asset); $asset_model =& $draft_model->getLink('asset_id', $draft_model->asset); if ($asset_model) { $this->set(array('draft' => $draft_model->toArray(), 'asset_name' => $asset_ctrl->page_title ? $asset_ctrl->page_title : Inflector::humanize($asset_ctrl->name), 'asset' => $draft_model->asset)); $this->set($asset_model->toArray()); $this->setAppend('drafts', $this->render(array('action' => 'draft_record', 'return' => true))); } unset($asset_ctrl); unset($asset_model); } } else { $this->set('drafts', $this->render(array('action' => 'no_drafts', 'return' => true))); } } } // load all workflow output into this variable to be assigned later $workflow_html = ''; if (SITE_WORKFLOW) { $sidebar_content .= $this->render(array('action' => 'workflow_description', 'return' => true)); $user_id = $this->_auth->currentUserId(); // If user is an admin, and has any unsubmitted workflow in groups they don't belong to, display them first if ($this->_auth->getAuthData('user_level') >= N_USER_ADMIN) { $workflow =& NController::factory('workflow'); $workflow_model =& NModel::factory('workflow'); $workflow_model_pk = $workflow_model->primaryKey(); $workflow_model->cms_modified_by_user = $user_id; $workflow_model->submitted = 0; if ($workflow_model->find(array('order_by' => 'page_id'))) { $admin_workflow_html = ''; $this->set('workflow_section', 'Unsubmitted Admin Workflows'); $workflow_html .= $this->render(array('action' => 'workflow_section', 'return' => true)); $page_id = 0; $page_count = 0; $page_workflows = array(); while ($workflow_model->fetch()) { $workflow_users_model =& NModel::factory('workflow_users'); $workflow_users_model->workflow_group_id = $workflow_model->workflow_group_id; $workflow_users_model->user_id = $workflow_model->cms_modified_by_user; if ($workflow_users_model->find()) { unset($workflow_users_model); continue; } unset($workflow_users_model); $unsubmitted[] = $workflow_model->{$workflow_model_pk}; $page_content_model =& NModel::factory('page_content'); $page_content_model->get($workflow_model->page_content_id); $page_model =& $page_content_model->getLink('page_id', 'page'); $asset_controller =& NController::factory($workflow_model->asset); $asset_model =& $asset_controller->getDefaultModel(); $asset_model->get($workflow_model->asset_id); $this->convertDateTimesToClient($asset_model); $action = $workflow->actionToString($workflow_model->action); $cascade_delete = $page_content_model->cms_workflow ? true : false; // set the page title for the following pages $this->set('page_title', ''); if ($workflow_model->page_id == $page_id) { $page_count++; } else { $this->set('page_title', $page_model->title); $admin_workflow_html .= $this->workflowPageSubmit($page_workflows); $page_id = $workflow_model->page_id; $page_count = 0; $page_workflows = array(); } $page_workflows[] = $workflow_model->{$workflow_model_pk}; $user =& $workflow_model->getLink('cms_modified_by_user', 'cms_auth'); $this->set(array('process' => 'submit', 'cascade_delete' => $cascade_delete, 'approved' => $workflow_model->approved, 'action' => $action, 'workflow' => $workflow_model->toArray(), 'page' => $page_model->toArray(), 'asset' => $asset_controller, 'row' => $asset_model->toArray(), 'user' => $user ? $user->toArray() : false)); $admin_workflow_html .= $this->render(array('action' => 'workflow_record', 'return' => true)); } $admin_workflow_html .= $this->workflowPageSubmit($page_workflows); if ($admin_workflow_html) { $this->set(array('workflow_title' => 'Admin Workflows')); $workflow_html .= $this->render(array('action' => 'workflow', 'return' => true)) . $admin_workflow_html; unset($admin_workflow_html); } } unset($workflow_model); unset($workflow); } $workflow_users =& $this->loadModel('workflow_users'); $workflow_users->user_id = $user_id; if ($workflow_users->find()) { while ($workflow_users->fetch()) { // instantiate workflow group object $workflow_group =& $workflow_users->getLink('workflow_group_id', 'workflow_group'); // render current workflow group $this->set($workflow_group->toArray()); $workflow_html .= $this->render(array('action' => 'workflow', 'return' => true)); // instantiate workflow objects $workflow =& NController::factory('workflow'); $workflow_model =& $workflow->getDefaultModel(); $workflow_model_pk = $workflow_model->primaryKey(); // find unsubmitted workflows that belong to this user $workflow_model->submitted = 0; $workflow_model->completed = 0; $workflow_model->workflow_group_id = $workflow_group->{$workflow_group->primaryKey()}; $workflow_model->cms_modified_by_user = $user_id; $unsubmitted = array(); if ($workflow_model->find(array('order_by' => 'page_id, asset, asset_id, id'))) { $this->set('workflow_section', 'Unsubmitted Workflows'); $workflow_html .= $this->render(array('action' => 'workflow_section', 'return' => true)); $page_id = 0; $page_count = 0; $page_workflows = array(); while ($workflow_model->fetch()) { $unsubmitted[] = $workflow_model->{$workflow_model_pk}; $page_content_model =& $workflow_model->getLink('page_content_id', 'page_content'); if (!$page_content_model) { continue; } $page_model =& $page_content_model->getLink('page_id', 'page'); $asset_controller =& NController::factory($workflow_model->asset); $asset_model =& $asset_controller->getDefaultModel(); $asset_model->get($workflow_model->asset_id); $this->convertDateTimesToClient($asset_model); $action = $workflow->actionToString($workflow_model->action); // set the page title for the following pages $this->set('page_title', ''); if ($workflow_model->page_id == $page_id) { $page_count++; } else { $this->set('page_title', $page_model->title); $workflow_html .= $this->workflowPageSubmit($page_workflows); $page_id = $workflow_model->page_id; $page_count = 0; $page_workflows = array(); } $page_workflows[] = $workflow_model->{$workflow_model_pk}; $user =& $workflow_model->getLink('cms_modified_by_user', 'cms_auth'); $this->convertDateTimesToClient($workflow_model); $this->set(array('process' => 'submit', 'list_only' => false, 'approved' => $workflow_model->approved, 'action' => $action, 'workflow' => $workflow_model->toArray(), 'page' => $page_model->toArray(), 'asset' => $asset_controller, 'row' => $asset_model->toArray(), 'user' => $user ? $user->toArray() : false)); $workflow_html .= $this->render(array('action' => 'workflow_record', 'return' => true)); } $workflow_html .= $this->workflowPageSubmit($page_workflows); } // find in process workflows, resetting the model object first $workflow_model->reset(); $workflow_model->workflow_group_id = $workflow_group->{$workflow_group->primaryKey()}; $workflow_model->completed = 0; $conditions = ''; foreach ($unsubmitted as $id) { $conditions .= ($conditions ? ' AND ' : '') . "{$workflow_model_pk}!={$id}"; } $this->set('workflow_section', 'Workflows in Process'); $workflow_html .= $this->render(array('action' => 'workflow_section', 'return' => true)); $workflow_html_content = ''; if ($workflow_model->find(array('conditions' => $conditions, 'order_by' => 'page_id, asset, asset_id, id'))) { $workflow_models = array(); while ($workflow_model->fetch()) { $workflow_models[] = clone $workflow_model; } $i = 0; $current_asset = ''; foreach ($workflow_models as $w_model) { if ($w_model->submitted == 0) { continue; } if ($current_asset != $w_model->asset . $w_model->asset_id) { $current_asset = $w_model->asset . $w_model->asset_id; if (!($page_content_model =& $w_model->getLink('page_content_id', 'page_content'))) { continue; } if (!($page_model =& $page_content_model->getLink('page_id', 'page'))) { continue; } $user_def = $workflow->getWorkflowUser($w_model->workflow_group_id); if ($user_def) { $user_role = $user_def->role; $user_id = $user_def->user_id; } $user_rights = $workflow->getWorkflowUserRights($page_model); $i = 0; } $asset_controller =& NController::factory($w_model->asset); $asset_model =& $asset_controller->getDefaultModel(); $asset_model->get($w_model->asset_id); $this->convertDateTimesToClient($asset_model); $action = $workflow->actionToString($w_model->action); $all_workflow_users = $workflow->getWorkflowUsers($workflow_model->workflow_group_id); if (count($all_workflow_users) < 2) { $i++; } if ($i == 0) { if ($user_rights == WORKFLOW_RIGHT_EDIT) { $process = 'In Process - ' . ($w_model->approved ? 'Approved' : 'Unapproved'); } else { if ($user_rights & WORKFLOW_RIGHT_EDIT) { // this is someone with editing rights and more. Could be the same user that submitted it. $process = $w_model->approved ? 'In Process - Approved' : 'editapprove'; } else { // This is someone up the line. Let them know something's coming, but they don't need to know what yet. if ($w_model->approved) { $process = 'Approved'; } else { $process = 'A workflow has been started. You will be notified if/when you need to take action.'; } } } } else { if ($i == 1) { if ($user_rights == WORKFLOW_RIGHT_EDIT) { $process = 'In Process - ' . ($w_model->approved ? 'Approved' : 'Unapproved'); } else { if ($user_rights & WORKFLOW_RIGHT_APPROVE && $user_rights & WORKFLOW_RIGHT_PUBLISH) { // this is someone with Approval rights. Could be the same user that submitted it $process = 'approve'; } else { $process = 'In Process - ' . ($w_model->approved ? 'Approved' : 'Unapproved'); } } } } $user =& $w_model->getLink('cms_modified_by_user', 'cms_auth'); $this->convertDateTimesToClient($w_model); $this->set(array('process' => $process, 'list_only' => false, 'approved' => $w_model->approved, 'action' => $action, 'workflow' => $w_model->toArray(), 'page' => $page_model->toArray(), 'asset' => $asset_controller, 'row' => $asset_model->toArray(), 'user' => $user ? $user->toArray() : false)); $workflow_html_content .= $this->render(array('action' => 'workflow_record', 'return' => true)); $i++; } } $workflow_html .= $workflow_html_content ? $workflow_html_content : $this->render(array('action' => 'workflow_norecords', 'return' => true)); // find completed workflows, resetting the model object first $workflow_model->reset(); $workflow_model->workflow_group_id = $workflow_group->{$workflow_group->primaryKey()}; $workflow_model->completed = 1; $workflow_model->parent_workflow = 0; // bad timg - shouldn't do this here $workflow_html .= '<div style="background:#EEE;border:1px solid #AAA;padding:4px;">' . "\n"; $this->set('workflow_section', 'Completed Workflows'); $workflow_html .= $this->render(array('action' => 'workflow_section', 'return' => true)); if ($workflow_model->find(array('conditions' => $conditions, 'order_by' => 'cms_created DESC', 'limit' => 5))) { $workflow_models = array(); while ($workflow_model->fetch()) { $page_model =& NModel::factory('page'); $page_model->{$page_model->primaryKey()} = $workflow_model->page_id; // if the page is not deleted, this works if (!$page_model->find(null, true)) { // otherwise, specify a deleted page and try again $page_model->reset(); $page_model->{$page_model->primaryKey()} = $workflow_model->page_id; $page_model->cms_deleted = 1; $page_model->find(null, true); } $page_values = $page_model ? $page_model->toArray() : false; $asset_controller =& NController::factory($workflow_model->asset); $asset_model =& $asset_controller->getDefaultModel(); if (!$asset_model->get($workflow_model->asset_id)) { $asset_model->reset(); $asset_model->cms_deleted = 1; $asset_model->get($workflow_model->asset_id); } $this->convertDateTimesToClient($asset_model); $action = $workflow->actionToString($workflow_model->action); $user =& $workflow_model->getLink('cms_modified_by_user', 'cms_auth'); $this->convertDateTimesToClient($workflow_model); $values = array('process' => null, 'list_only' => true, 'approved' => $workflow_model->approved, 'action' => $action, 'workflow' => $workflow_model->toArray(), 'asset' => $asset_controller, 'row' => $asset_model->toArray(), 'page' => $page_values, 'user' => $user ? $user->toArray() : false); $this->set($values); $workflow_html .= $this->render(array('action' => 'workflow_record', 'return' => true)); } } $workflow_html .= '</div>' . "\n"; } } else { $workflow_html .= $this->render(array('action' => 'no_workflows', 'return' => true)); } $this->set('workflow', $workflow_html); } $this->set('SIDEBAR_CONTENT', $sidebar_content); $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'nterchange_training', 'return' => true))); $this->setAppend('SIDEBAR_CONTENT', $this->render(array('action' => 'dashboard_client_sidebar_content', 'return' => true))); $this->render(array('layout' => 'default')); }