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', '
There were no results found for the specified date.
'); + } + // 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 dateStartEnd($params=false){ + $y = (isset($params['Y']) && $params['Y']) ? $params['Y'] : false; + $m = (isset($params['F']) && $params['F']) ? $params['F'] : false; + $d = (isset($params['d']) && $params['d']) ? $params['d'] : false; + + $date = array(); + $date['month'] = false; + + if ($y && $d && $m){ + // Fully qualified + $date_arg = date('Y-m-d', strtotime("$y-$m-$d")); + $date['start'] = NDate::convertTimeToUTC($date_arg . ' 00:00:00', '%Y-%m-%d %H:%M:%S'); + $date['end'] = NDate::convertTimeToUTC($date_arg . ' 23:59:59', '%Y-%m-%d %H:%M:%S'); + $date['used'] = $date_arg; + return($date); + } + + if ((! $params['d']) && ( $y && $params['F'] )) { + // One Month + $date_arg = date('Y-m-d', strtotime("$y-$m-1")); + $days_in_month = date('t', strtotime($date_arg)); + $month_end = date('Y-m-d', strtotime("$y-$m-$days_in_month")); + $date['start'] = NDate::convertTimeToUTC($date_arg . ' 00:00:00', '%Y-%m-%d %H:%M:%S'); + $date['end'] = NDate::convertTimeToUTC($month_end . ' 23:59:59', '%Y-%m-%d %H:%M:%S'); + $date['used'] = "$y-$m-1"; + $date['month'] = true; + return $date; + } + + // Default to one day: today + $date['start'] = NDate::convertTimeToUTC(date('Y-m-d') . ' 00:00:00', '%Y-%m-%d %H:%M:%S'); + $date['end'] = NDate::convertTimeToUTC(date('Y-m-d') . ' 23:59:59', '%Y-%m-%d %H:%M:%S'); + $date['used'] = date('Y-m-d'); + return($date); + + } + + function page($parameter) { + $page_id = $parameter; + $this->_auth = new NAuth; + $this->auto_render = false; + // set up the search form + include_once 'n_quickform.php'; + // search for the date + /* @var $model cmsAuditTrail */ + $model = &$this->getDefaultModel(); + $model->page_id = $page_id; + if ($model->find(array('order_by'=>'cms_created DESC'))) { + $html = ''; + while ($model->fetch()) { + // Actually turn the id's into something readable. + $info = $this->humanizeAuditTrailRecord($model); + $this->set($info); + $html .= $this->render(array('action'=>'page_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', 'There were no results found for the specified page.
'); + } + // 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->loadSubnav($parameter); + $this->render(array('layout'=>'default')); + } + + /** + * humanizeAuditTrailRecord - Turns the id's in the cms_audit_trail table into human readable + * English. + * + * @param object An object which contains an audit trail record. + * @return array An array of human readable information about that audit trail record. + **/ + function humanizeAuditTrailRecord($model) { + $this->convertDateTimesToClient($model); + $info = array('user'=>false, 'asset'=>false, 'workflow'=>false, 'workflow_group'=>false, 'page'=>false, 'page_content'=>false); + if ($model->user_id) { + if ($model->user_id == $model->website_user_id) { + // This is a hack for timed_removal of content - see the cms_audit_trail model for info. + $info['user'] = array('id'=>$model->website_user_id, 'real_name'=>$model->website_user_name, 'email'=>$model->website_user_email); + } else { + $info['user'] = $this->getAuditInfo('users', $model->user_id); + } + } + if ($model->workflow_id) { + $info['workflow'] = $this->getAuditInfo('workflow', $model->workflow_id); + } + if ($model->asset && $model->asset != 'page' && $model->asset_id) { + $info['asset'] = $this->getAuditInfo($model->asset, $model->asset_id); + $info['asset_type'] = $model->asset; + $info['asset_name'] = Inflector::humanize($model->asset); + } else if ($info['workflow']) { + $info['asset'] = $this->getAuditInfo($info['workflow']['asset'], $info['workflow']['asset_id']); + $info['asset_type'] = $info['workflow']['asset']; + $info['asset_name'] = Inflector::humanize($info['workflow']['asset']); + } + if ($model->workflow_group_id) { + $info['workflow_group'] = $this->getAuditInfo('workflow_group', $model->workflow_group_id); + } else if ($info['workflow']) { + // if there's no workflow_group_id right in the audit trail, try the workflow['workflow_group_id'] + $info['workflow_group'] = $this->getAuditInfo('workflow_group', $info['workflow']['workflow_group_id']); + } + if ($model->page_content_id) { + $info['page_content'] = $this->getAuditInfo('page_content', $model->page_content_id); + } else if ($info['workflow']) { + // if there's no page_content_id right in the audit trail, try the workflow['page_content_id'] + $info['page_content'] = $this->getAuditInfo('page_content', $info['workflow']['page_content_id']); + } + if ($model->page_id || $model->asset == 'page') { + $info['page'] = $model->asset == 'page'?$this->getAuditInfo('page', $model->asset_id):$this->getAuditInfo('page', $model->page_id); + } else if ($info['page_content']) { + // if there's no page_id right in the audit trail, try the page_content['page_id'] + $info['page'] = $this->getAuditInfo('page', $info['page_content']['page_id']); + } else if ($info['workflow']) { + // if there's no page_id or page_content_id right in the audit trail, try the workflow['page_id'] + $info['page'] = $this->getAuditInfo('page', $info['workflow']['page_id']); + } + $info['action_taken'] = $this->actionToText($model->action_taken); + $info['ip'] = $model->ip; + $info['created'] = $model->cms_created; + return $info; + } + + /** + * 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 = 'Click here to generate a private RSS feed
'; + } else { + $rss = 'Private RSS Feed of Audit Trail Activity - Regenerate Token
'; + } + + // Then show the link so that they can put it into their feed reader. + $this->set('rss_feed', $rss); + } + unset($auth); + } + + /** + * getAuditInfo - gets additional audit trail information by looking up foreign keys. + * + * @param string Name of a particular model. + * @param int Id of a record in that particular model. + * @return array Information related to $model_name and $id. + **/ + function getAuditInfo($model_name, $id) { + // checks for deleted and non-deleted records using special field + $info = false; + $fctrl = &NController::singleton($model_name); + if ($fctrl && $fmodel = &$fctrl->getDefaultModel()) { + $fmodel->reset(); + if (!$fmodel->get($id)) { + $fmodel->reset(); + $fields = $fmodel->fields(); + if (in_array('cms_deleted', $fields)) { + $fmodel->cms_deleted = 1; + } + $fmodel->get($id); + } + $info = $fmodel->{$fmodel->primaryKey()}?$fmodel->toArray():false; + if ($info && (!isset($info['_headline']) || !$info['_headline'])) { + $info['_headline'] = $fmodel->makeHeadline(); + } + unset($fmodel); + } + return $info; + } + + /** + * insert - Actually insert a cms_audit_trail record. Must be logged in to nterchange + * for this to succeed. + * NOTE: If you need to log an audit trail record without being logged in (eg. timed content removal) + * there is an alternate method in the cms_audit_trail model. + * + * @param array Required params - asset, asset_id, action_taken + * @return void + **/ + function insert($params=array()) { + $this->_auth = new NAuth; + 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 = &$this->getDefaultModel(); + // apply fields in the model + $fields = $model->fields(); + foreach ($fields as $field) { + $model->$field = isset($params[$field])?$params[$field]:null; + } + $model->user_id = $this->_auth->currentUserID(); + $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->_auth->currentUserID(); + } + $model->insert(); + } + + /** + * actionToText - Convert an action_id to it's human readable explanation. + * + * @param int The id of the action. + * @return string What that id actually means. + **/ + function actionToText($action) { + $txt = ''; + switch ($action) { + case AUDIT_ACTION_INSERT: + $txt = 'Inserted'; + break; + case AUDIT_ACTION_UPDATE: + $txt = 'Updated'; + break; + case AUDIT_ACTION_DELETE: + $txt = 'Deleted'; + break; + case AUDIT_ACTION_CONTENT_ADDEXISTING: + $txt = 'Added Existing Content'; + break; + case AUDIT_ACTION_CONTENT_ADDNEW: + $txt = 'Added New Content to a page'; + break; + case AUDIT_ACTION_CONTENT_REMOVE: + $txt = 'Removed Content from a page'; + break; + case AUDIT_ACTION_WORKFLOW_START: + $txt = 'Submitted Workflow'; + break; + case AUDIT_ACTION_WORKFLOW_SUBMIT: + $txt = 'Submitted Workflow'; + break; + case AUDIT_ACTION_WORKFLOW_APPROVE: + $txt = 'Approved Workflow'; + break; + case AUDIT_ACTION_WORKFLOW_APPROVEPUBLISH: + $txt = 'Approved & Published Workflow'; + break; + case AUDIT_ACTION_WORKFLOW_APPROVEREMOVE: + $txt = 'Approved & Removed Workflow Content'; + break; + case AUDIT_ACTION_WORKFLOW_DECLINE: + $txt = 'Declined Workflow'; + break; + case AUDIT_ACTION_DRAFT_SAVE: + $txt = 'Saved a Draft'; + break; + case AUDIT_ACTION_DRAFT_DELETE: + $txt = 'Deleted a Draft'; + break; + case AUDIT_ACTION_DELETE_ASSET_VERSIONS: + $txt = 'Removed all old content versions'; + break; + case AUDIT_ACTION_LOGIN: + $txt = 'Logged into nterchange'; + break; + } + return $txt; + } + + // override all the crud functions so that no one can edit or manually create an audit trail + // insert is already overridden above with a custom method + function create() { + $this->redirectTo('viewlist'); + } + function edit() { + $this->redirectTo('viewlist'); + } + function update() { + $this->redirectTo('viewlist'); + } + function delete() { + $this->redirectTo('viewlist'); + } + + function &getDefaultModel() { + $model = &$this->loadModel('cms_audit_trail'); + return $model; + } +} +?> diff --git a/app/controllers/cms_asset_info_controller.php b/app/controllers/cms_asset_info_controller.php new file mode 100644 index 0000000..4b119db --- /dev/null +++ b/app/controllers/cms_asset_info_controller.php @@ -0,0 +1,139 @@ + + * @copyright 2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class CmsAssetInfoController extends AdminController { + function __construct() { + $this->name = 'cms_asset_info'; + // set user level allowed to access the actions with required login + $this->user_level_required = N_USER_ADMIN; + $this->page_title = 'Assets'; + $this->login_required = true; + parent::__construct(); + } + + /** + * AssetList - Return an array of all assets in cms_asset_info table unless + * $connectable is set - then use $model->not_connectable to leave those + * assets out. + * + * @param boolean Whether you want only connectable assets. + * @return array An array with all of the possible assets. + **/ + function AssetList ($connectable=false) { + // Grab the list of available assets. + $assets = &NModel::factory($this->name); + if ($assets->find()) { + while ($assets->fetch()) { + $asset_list[] = $assets->toArray(); + } + unset($assets); + foreach ($asset_list as $asset) { + $model = &NModel::factory($asset['asset']); + // If you don't want any non_connectable assets in the array. + if ($model && $connectable && !isset($model->not_connectable)) { + $final_assets[] = $asset; + // Or if you just want them all. + } elseif($model && !$connectable) { + $final_assets[] = $asset; + } + unset($model); + } + return $final_assets; + } + } + + /** + * doesAssetModelFileExist - Check for the existance of an asset's model file. + * Check in the frontend and backend. + * + * @param string The name of the asset + * @return boolean Does it exist or not? + **/ + function doesAssetModelFileExist($asset){ + $full_path_filename = ASSET_DIR . '/models/' . $asset . '.php'; + if (file_exists($full_path_filename)) { + return true; + } else { + // Check in nterchange backend proper. + $full_path_filename = BASE_DIR . '/app/models/' . $asset . '.php'; + if (file_exists($full_path_filename)) { + return true; + } + return false; + } + } + + /** + * doesAssetControllerFileExist - Check for the existance of an asset's controller file. + * Check in the frontend and backend. + * + * @param string The name of the asset + * @return boolean Does it exist or not? + **/ + function doesAssetControllerFileExist($asset){ + $full_path_filename = ASSET_DIR . '/controllers/' . $asset . '_controller.php'; + if (file_exists($full_path_filename)) { + return true; + } else { + // Check in nterchange backend proper. + $full_path_filename = BASE_DIR . '/app/controllers/' . $asset . '_controller.php'; + if (file_exists($full_path_filename)) { + return true; + } + return false; + } + } + + /** + * 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 &getDefaultModel() { + $model = &$this->loadModel($this->name); + return $model; + } + + /** + * postGenerateForm - Just setting some validation rules for the forms. + * + * @return void + **/ + function postGenerateForm(&$form) { + $form->removeElement('__header__'); + $form->addRule('asset', 'We need to have an asset.', 'required', null, 'client'); + $form->addRule('asset', 'Letters, numbers, dashes and underscores - without a suffix, spaces or punctuation.', 'regex', '/^[a-zA-Z0-9_-]+$/', 'client'); + $form->addRule('asset_name', 'We need to have a name for this asset.', 'required', null, 'client'); + } +} +?> \ No newline at end of file diff --git a/app/controllers/cms_asset_template_controller.php b/app/controllers/cms_asset_template_controller.php new file mode 100644 index 0000000..49a4a60 --- /dev/null +++ b/app/controllers/cms_asset_template_controller.php @@ -0,0 +1,159 @@ + + * @copyright 2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class CmsAssetTemplateController extends AdminController { + function __construct() { + $this->name = 'cms_asset_template'; + // set user level allowed to access the actions with required login + $this->user_level_required = N_USER_ADMIN; + $this->login_required = true; + $this->page_title = 'Asset / Container Templates'; + parent::__construct(); + } + + function getAssetTemplate($asset, $container_id) { + $model = &NModel::factory($this->name); + $model->asset = (string)$asset; + $model->page_template_container_id = (int)$container_id; + $ret = ''; + if ($model->find(null, true)) { + $ret = $model->template_filename; + } + unset($model); + return $ret; + } + + function viewlist($page_template_container) { + $this->loadSubnav($page_template_container); + $this->auto_render = false; + $html = ''; + if (!$page_template_container) { + // This is a bit of a hack. + header ('Location: /nterchange/page_template/viewlist'); + } + $model = $this->getDefaultModel($this->name); + $model->page_template_container_id = $page_template_container; + $this->set('page_template_container_id', $page_template_container); + // Let's get the Container Name. + if ($page_template_container = $model->getLink('page_template_container_id', 'page_template_containers')) { + $this->set('page_template_container_name', $page_template_container->container_name); + // With the name, let's get the template name and filename too. + $page_template = &NModel::factory('page_template'); + $page_template->id = $page_template_container->page_template_id; + $this->set('page_template_id', $page_template_container->page_template_id); + if ($page_template->find()) { + while ($page_template->fetch()) { + $page_template_tmp = $page_template->toArray(); + $this->set('page_template_filename', $page_template_tmp['template_filename']); + $this->set('page_template_name', $page_template_tmp['template_name']); + } + } + } + if ($model->find()) { + while ($model->fetch()) { + $arr = $model->toArray(); + $arr['_headline'] = isset($arr['cms_headline']) && $arr['cms_headline']?$arr['cms_headline']:$model->makeHeadline(); + $models[] = $arr; + unset($arr); + $html .= $this->set('rows', $models); + } + $html .= $this->set(array('rows'=>$models, 'asset'=>$this->name, 'asset_name'=>$this->page_title?$this->page_title:Inflector::humanize($this->name))); + } else { + $this->set('notice', 'There are no assets associated with that container.'); + } + $html .= $this->set(array('asset'=>$this->name, 'asset_name'=>$this->page_title?$this->page_title:Inflector::humanize($this->name))); + $html .= $this->render(array('layout'=>'default')); + return $html; + } + + function create($parameter=null, $layout=true) { + $this->page_template_container_id = $parameter; + $this->loadSubnav($parameter); + parent::create($parameter); + } + + function edit($parameter) { + $this->page_template_container_id = $this->getPTCIFromId($parameter); + $this->set('page_template_container_id', $this->page_template_container_id); + $this->loadSubnav($parameter); + parent::edit($parameter); + } + + // Get page_template_container_id from cms_asset_template_id + 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 postGenerateForm(&$form) { + $form->removeElement('__header__'); + // Set the container in the menu as passed by $parameter + $container_group = &$form->getElement('page_template_container_id'); + $container_group->setSelected($this->page_template_container_id); + // Not sure I should do this - but it seems to help with confusion. + $container_group->freeze(); + + // Grab the asset list and create an array for QuickForm. + $assets = &NController::factory('cms_asset_info'); + $array_of_assets = $assets->AssetList(true); + foreach ($array_of_assets as $asset) { + $select_array[$asset['asset']] = $asset['asset_name']; + } + // Add the element in place of the current asset form item. + $form->removeElement('asset'); + $new_select = &$form->addElement('select', 'asset', 'Asset:', $select_array); + $form->insertElementBefore($form->removeElement('asset', false), 'template_filename'); + // Set the asset if passed by edit. + if (isset($this->passed_asset)) { + $new_select->setSelected($this->passed_asset); + } + $form->addRule('template_filename', 'We need to have a template filename.', 'required', null, 'client'); + $form->addRule('template_filename', 'Letters, numbers, dashes and underscores - without a suffix, spaces or punctuation.', 'regex', '/^[a-zA-Z0-9_-]+$/', 'client'); + } + + function doesAssetTemplateExist($filename, $asset){ + $full_path_filename = ASSET_DIR . '/views/' . $asset . '/' . $filename . '.' . DEFAULT_PAGE_EXTENSION; + if (file_exists($full_path_filename)) { + return true; + } else { + // Check in nterchange backend proper. + $full_path_filename = BASE_DIR . '/app/views/' . $asset . '/' . $filename . '.' . DEFAULT_PAGE_EXTENSION; + if (file_exists($full_path_filename)) { + return true; + } + return false; + } + } + + function &getDefaultModel() { + $model = &$this->loadModel('cms_asset_template'); + return $model; + } +} +?> \ No newline at end of file diff --git a/app/controllers/cms_drafts_controller.php b/app/controllers/cms_drafts_controller.php new file mode 100644 index 0000000..19c89d6 --- /dev/null +++ b/app/controllers/cms_drafts_controller.php @@ -0,0 +1,60 @@ + + * @copyright 2005-2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class CmsDraftsController extends AppController { + function __construct() { + $this->name = 'cms_drafts'; + // set user level allowed to access the actions with required login + $this->user_level_required = N_USER_NORIGHTS; + $this->login_required = true; + parent::__construct(); + } + + 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')); + } +} +?> \ No newline at end of file diff --git a/app/controllers/code_caller_controller.php b/app/controllers/code_caller_controller.php new file mode 100644 index 0000000..2eac01d --- /dev/null +++ b/app/controllers/code_caller_controller.php @@ -0,0 +1,103 @@ + + * @copyright 2005-2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class CodeCallerController extends AssetController { + function __construct() { + $this->name = 'code_caller'; + $this->versioning = true; + $this->base_view_dir = BASE_DIR; + parent::__construct(); + } + + function render($options) { + $in_nterchange = defined('IN_NTERCHANGE')?constant('IN_NTERCHANGE'):false; + $in_surftoedit = defined('IN_SURFTOEDIT')?constant('IN_SURFTOEDIT'):false; + if (!$in_nterchange || $in_surftoedit) { + $model = &$this->getDefaultModel(); + $content = $model->content; + require_once 'vendor/JSON.php'; + $json = new Services_JSON(); + if ($code = $json->decode($content) && !empty($code)) { + if (isset($code->controller) && isset($code->action)) { + $this->getContent((array) $code, $model->dynamic); + } + } else { + while (false !== ($pos = strpos($content, '{call'))) { + $pos2 = strpos($content, '}', $pos)+1; + $str = substr($content, $pos, $pos2-$pos); + // clean up the string + $str = trim(str_replace(array('{call ', '}'), '', $str)); + // replace value + $value = ''; + // find matches + preg_match_all('/\s?([^=]+)=[\"\']?([^\"\'\s$]+)[\"\']?/', $str, $matches); + // push the matches into an array if they exists + if (isset($matches[0])) { + $params = array(); + for ($i=0;$iWe have sent you a confirmation - please check your email and follow the instructions.
'; + } else { + $content = 'There was a problem - please click back and enter your email address again.
'; + } + $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')); + } + + /** + * confirmPasswordReset - Takes a token passed in the get string, verifies it and resets + * the corresponding password for that particular email address. + * + * @return void + **/ + function confirmPasswordReset() { + // Verify the token + $passed_token = $_GET['token']; + $cms_auth = NModel::factory('cms_auth'); + $cms_auth->confirmation_token = $passed_token; + // If it checks out, then send out the new password. + if ($cms_auth->find()) { + while ($cms_auth->fetch()) { + // If it's there - grab the email. + $email = $cms_auth->email; + // Set the confirmation_token to NULL + $cms_auth->confirmation_token = 'NULL'; + $cms_auth->save(); + // Reset it and send it out. + $cms_auth->resetPassword($email); + $content = 'The password was reset and emailed.'; + } + } else { + $content = 'There was a problem - please try again.'; + } + $this->set(array('MAIN_CONTENT'=>$content)); + $this->auto_render = false; + $this->render(array('layout'=>'login')); + } + +} +?> diff --git a/app/controllers/memcache_controller.php b/app/controllers/memcache_controller.php new file mode 100644 index 0000000..d48dd6d --- /dev/null +++ b/app/controllers/memcache_controller.php @@ -0,0 +1,41 @@ + + * @copyright 2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + * @since Version 3.1.17 + * @todo Expose this if you're actually running a memcached server. + */ +class MemcacheController extends AppController { + function __construct() { + $this->login_required = true; + parent::__construct(); + } + + /** + * index - Just show the memcache server's statistics. + * + * @return void + **/ + function index() { + $this->auto_render = true; + $memcache_obj = new Memcache; + $memcache_obj->addServer(MEMCACHED_SERVER, MEMCACHED_SERVER_PORT); + $stats = $memcache_obj->getExtendedStats(); + varDump($stats); + } +} +?> \ No newline at end of file diff --git a/app/controllers/nterchange_controller.php b/app/controllers/nterchange_controller.php new file mode 100644 index 0000000..7993bed --- /dev/null +++ b/app/controllers/nterchange_controller.php @@ -0,0 +1,73 @@ + + * @copyright 2005-2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class nterchangeController extends AppController { + var $base_dir = APP_DIR; + function __construct() { + if (defined('ADMIN_URL') && constant('ADMIN_URL') != false && is_string(ADMIN_URL) && preg_match('|^/' . APP_DIR . '/|', $_SERVER['REQUEST_URI'])) { + if (!preg_match('|http[s]?://' . $_SERVER['SERVER_NAME'] . '|', ADMIN_URL)) { + $loc = preg_replace('|/$|', '', ADMIN_URL) . $_SERVER['REQUEST_URI']; + // if you don't want a 404 and want to redirect instead, comment out this line + die(NDispatcher::error404()); + header('Location:' . $loc); + exit; + } + } + if (is_null($this->name)) + $this->name = 'nterchange'; + if (is_null($this->base_view_dir)) + $this->base_view_dir = BASE_DIR; + if (!defined('IN_NTERCHANGE')) define('IN_NTERCHANGE', preg_match('|^/' . APP_DIR . '|', NServer::env('REQUEST_URI'))?true:false); + parent::__construct(); + } + + function navigation($current_section) { + if (!isset($this->_auth)) return; + $current_user_level = $this->_auth->getAuthData('user_level'); + // need to loop through other constructors and see + // if they belong in the navigation tabs + $navigation = array(); + $navigation[] = array('title'=>'Dashboard', 'controller'=>'dashboard', 'class'=>''); + $navigation[] = array('title'=>'Site Admin', 'controller'=>'site_admin', 'class'=>''); + if ($current_user_level >= N_USER_ADMIN) { + $navigation[] = array('title'=>'Content', 'controller'=>'content', 'class'=>''); + } + if (SITE_WORKFLOW) { + $navigation[] = array('title'=>'Workflow', 'controller'=>'workflow_group', 'class'=>''); + } + $navigation[] = array('title'=>'Admin', 'controller'=>'admin', 'class'=>'right'); + if ($current_user_level < N_USER_ADMIN) { + $navigation[] = array('title'=>'User', 'controller'=>'users', 'class'=>'right'); + } + foreach ($navigation as $k=>$nav) { + $ctrl = &NController::factory($nav['controller']); + $ctrl->_auth = &$this->_auth; + if (!$ctrl || !$ctrl->checkUserLevel()) { + unset($navigation[$k]); + continue; + } + if ($this->name == $ctrl->name || is_a($this, get_class($ctrl))) { + $navigation[$k]['class'] .= ($navigation[$k]['class']?' ':'') . 'current'; + } + } + return $navigation; + } +} diff --git a/app/controllers/page_content_controller.php b/app/controllers/page_content_controller.php new file mode 100644 index 0000000..510694c --- /dev/null +++ b/app/controllers/page_content_controller.php @@ -0,0 +1,732 @@ + + * @copyright 2005-2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class PageContentController extends nterchangeController { + function __construct() { + $this->name = 'page_content'; + parent::__construct(); + $this->login_required = true; + $this->public_actions = array('select_content_type', 'add_new_content', 'add_existing_content', 'remove_content', 'reorder'); + // set user level allowed to access the actions with required login + $this->user_level_required = N_USER_NORIGHTS; + $this->base_view_dir = ROOT_DIR; + } + + function selectContentType($parameter) { + $page_model = &$this->loadModel('page'); + $page_model->get($parameter); + // instantiate form, + include_once 'n_quickform.php'; + $form = new NQuickForm('select_content_type'); + $values = $form->getSubmitValues(); + + if(isset($values['template_container_id'])){ + $template_container_id = $values['template_container_id']; + } else { + if(isset($this->params['template_container_id'])){ + $template_container_id = $this->params['template_container_id']; + } else { + $template_container_id = false; + } + } + $form->addElement('header', null, 'Do you wish to add new or existing content to the "' . $page_model->title . '" page?'); + // next action + $options = array('addnewcontent'=>'New Content', 'addexistingcontent'=>'Existing Content'); + $form->addElement('select', '_action', 'Select', $options); + // assets for this container + $model = &$this->loadModel('cms_asset_template'); + $pk = $model->primaryKey(); + $model->page_template_container_id = $template_container_id; + $options = array(); + if ($model->find(array('join'=>'INNER JOIN cms_asset_info ON cms_asset_info.asset=' . $model->tableName() . '.asset'))) { + while ($model->fetch()) { + $options[$model->asset] = $model->asset_name; + } + } + $form->addElement('select', 'asset', 'Asset', $options); + // hidden values + $form->addElement('hidden', 'page_id', $parameter); + $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__', 'go'); + // rules + $form->addRule('asset', '', 'required'); + $form->addRule('template_container_id', '', 'required'); + // validation + if ($form->validate()) { + $values = $form->exportValues(); + $params = array('asset'=>$this->params['asset'], 'template_container_id'=>$this->params['template_container_id']); + if (isset($this->params['_referer'])) { + $params['_referer'] = $this->params['_referer']; + } + $this->redirectTo($values['_action'], $parameter, $params); + } + unset($page_model); + $this->auto_render = false; + $this->page_title = 'Select Content Type'; + $this->set('form', $form->toHTML()); + $this->render(array('action'=>'form', 'layout'=>'plain')); + } + + function addNewContent($parameter, $load_model_content=false) { + $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; + $asset_controller = &NController::singleton($asset); + $asset_controller->_auth = new NAuth(); + + // load the model layer with info + $asset_model = &$asset_controller->getDefaultModel(); + + // create the form + include_once 'controller/form.php'; + $cform = new ControllerForm($asset_controller, $asset_model); + $form = &$cform->getForm(); + // check for workflow + if (SITE_WORKFLOW) { + // get the users rights and bit compare them below + $workflow = &NController::factory('workflow'); + $user_rights = $workflow->getWorkflowUserRights($page_model); + $workflow_group = &$workflow->getWorkflowGroup($page_model); + if ($workflow_group && !($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); + } + // timed content + $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); + $form->addElement('submit', '__submit_timed__', 'Add Scheduled Content'); + // page_content values + $form->addElement('hidden', 'template_container_id', $template_container_id); + $form->addElement('hidden', 'asset', $asset); + if (isset($this->params['_referer'])) { + $form->addElement('hidden', '_referer', urlencode($this->params['_referer'])); + } + // assign the info and render + $asset_controller->base_dir = APP_DIR; + $assigns = array(); + $table = $asset_model->table(); + $fields = $asset_model->fields(); + if ($form->validate()) { + $values = $form->getSubmitValues(); + if (in_array('cms_created', $fields)) { + $asset_model->cms_created = $asset_model->now(); + } + if (in_array('cms_modified', $fields)) { + $asset_model->cms_modified = $asset_model->now(); + } + // set the user id if it's applicable and available + if (in_array('cms_modified_by_user', $fields)) { + $asset_model->cms_modified_by_user = isset($asset_controller->_auth)?$asset_controller->_auth->currentUserId():0; + } + $referer = isset($values['_referer'])?$values['_referer']:false; + if ($referer) { + // cheat and remove the referer from the form oject so it doesn't redirect + if (isset($form->_submitValues['_referer'])) unset($form->_submitValues['_referer']); + } + $success = $form->process(array($cform, 'processForm')); + $asset_id = $asset_model->{$asset_model->primaryKey()}; + if ($success) { + $values = $form->exportValues(); + $model = &$this->loadModel($this->name); + $workflow_active = false; + $workflow_required = false; + if (SITE_WORKFLOW) { + $workflow = &NController::factory('workflow'); + if ($workflow_group_model = $workflow->getWorkflowGroup($page_model)) { + $workflow_required = true; + } + if ($workflow_required && isset($values['__submit_workflow__'])) { + $workflow_active = true; + } + } + $model->page_id = $parameter; + $model->page_template_container_id = $values['template_container_id']; + $model->content_asset = $values['asset']; + $model->content_asset_id = $asset_id; + // prep the timed content values if they exist + if (isset($values['timed_start'])) { + $values['timed_start'] = NDate::arrayToDate($values['timed_start']); + $values['timed_start'] = NDate::convertTimeToUTC($values['timed_start']); + } + if (isset($values['timed_end'])) { + $values['timed_end'] = NDate::arrayToDate($values['timed_end']); + $values['timed_end'] = NDate::convertTimeToUTC($values['timed_end']); + } + // + if (!$workflow_active) { + if (isset($values['timed_start'])) $model->timed_start = $values['timed_start']; + if (isset($values['timed_end'])) $model->timed_end = $values['timed_end']; + } + if ($workflow_required) { + $model->cms_workflow = 1; + } + $model->cms_created = $model->now(); + $model->cms_modified = $model->now(); + $model->cms_modified_by_user = $this->_auth->currentUserID(); + if ($workflow_active) { + // set page_content cms_workflow to 1 so it can't show up + $model->cms_workflow = 1; + } + $model->insert(); + // do the workflow stuff if appropriate + if ($workflow_active) { + $page_content_id = $model->{$model->primaryKey()}; + $workflow_values = array(); + $workflow_values['page_content_id'] = $page_content_id; + $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()}; + // add timed content + if (isset($values['timed_start'])) $workflow_values['timed_start'] = $values['timed_start']; + if (isset($values['timed_end'])) $workflow_values['timed_end'] = $values['timed_end']; + $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_ADDNEW, $asset_controller); + // set page_content cms_workflow to 1 so it can't show up + } + // delete the page cache + $page = &NController::singleton('page'); + $page->deletePageCache($model->page_id); + 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_model->{$asset_model->primaryKey()}, 'action_taken'=>AUDIT_ACTION_CONTENT_ADDNEW, 'page_content_id'=>$model->{$model->primaryKey()}, 'page_id'=>$model->page_id)); + unset($audit_trail); + } + unset($page); + unset($model); + } + 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; + } else { + if ($asset_model) { + $this->set(array('form'=>$form->toHTML(), 'asset'=>$asset_controller->name, 'asset_name'=>Inflector::humanize($asset_controller->name))); + } + } + $this->auto_render = false; + $this->page_title = 'Add New Content to "' . $page_model->title . '"'; + $this->render(array('action'=>'form', '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); + } + + function copyExistingContent($parameter) { + $params = $this->params; + if (!isset($params['asset']) || !isset($params['asset_id']) || !isset($params['template_container_id'])) { + header('Location:/' . APP_DIR . '/'); + } + $asset_controller = &NController::singleton($params['asset']); + $asset_model = &$asset_controller->getDefaultModel(); + $asset_model->get($params['asset_id']); + $asset_model->{$asset_model->primaryKey()} = null; + $asset_model->cms_headline = null; + $this->flash->set('notice', 'The content you chose already belongs to another Workflow Group.You have not entered any search queries - please enter one in the form above.
'; + } + return $html; + } + + function search404() { + if ($this->getParam('search')) { + return $this->search(); + } + $uri = NServer::env('PHP_SELF'); + $words = explode('/', $uri); + // remove any empty elements + foreach ($words as $i=>$val) { + if(empty($val)){ + unset($words[$i]); + } + } + $this->setParam('search', urldecode(implode(' ', $words))); + return $this->search(); + } + + function cleanupItem($var) { + include_once 'model/value_cast.php'; + $var = ValueCast::toLatinISO($var); + // some weird mnogosearch characters to replace + $var = preg_replace('/\\x02/', '', $var); + $var = preg_replace('/\\x03/', '', $var); + return $var; + } +} +?> diff --git a/app/controllers/settings_controller.php b/app/controllers/settings_controller.php new file mode 100644 index 0000000..a304c80 --- /dev/null +++ b/app/controllers/settings_controller.php @@ -0,0 +1,109 @@ + + * @copyright 2005-2007 nonfiction studios inc. + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version SVN: $Id$ + * @link http://www.nterchange.com/ + */ +class SettingsController extends nterchangeController { + function __construct() { + $this->name = 'settings'; + // set user level allowed to access the actions with required login + $this->user_level_required = N_USER_NORIGHTS; + // $this->public_actions = array(); + $this->login_required = true; + parent::__construct(); + } + + function &getDefaultModel() { + return $this->loadModel('cms_settings'); + } + + function index() { + $this->redirectTo('viewlist'); + $this->auto_render = false; + $model = &$this->getDefaultModel(); + + $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 show($parameter) { + $model = &$this->getDefaultModel(); + $model->user_id = (int) $this->_auth->currentUserId(); + return parent::show($parameter); + } + + function edit($parameter) { + $model = &$this->getDefaultModel(); + $model->user_id = (int) $this->_auth->currentUserId(); + $this->flash->set('notice', 'Your preference has been saved.'); + return parent::edit($parameter); + } + + function create($parameter) { + $model = &$this->getDefaultModel(); + $model->user_id = (int) $this->_auth->currentUserId(); + $this->flash->set('notice', 'Your preference has been saved.'); + return parent::create($parameter); + } + + function getSettingDescription($setting) { + switch ($setting) { + case SETTINGS_EDITOR: + $ret = 'WYSIWYG EditorYour search on {$date|date_format:'%b %e, %Y'} found {$result_count} matches.
+{$rss_feed} +{$audit_trail} diff --git a/app/views/ck_upload/image_browse.html b/app/views/ck_upload/image_browse.html new file mode 100644 index 0000000..bfbf25b --- /dev/null +++ b/app/views/ck_upload/image_browse.html @@ -0,0 +1,15 @@ + + +{literal} + +{/literal} + ++The Dashboard is your nterchange home page. It gives you an overview of what the website is doing and provides the links to where you can find out more. +
+ +{if $drafts} ++Any Drafts that you have saved appear here as a reminder that they are waiting for your completion. +
+{/if} \ No newline at end of file diff --git a/app/views/dashboard/draft_record.html b/app/views/dashboard/draft_record.html new file mode 100644 index 0000000..5006b92 --- /dev/null +++ b/app/views/dashboard/draft_record.html @@ -0,0 +1,13 @@ ++You do not have any drafts saved. +
\ No newline at end of file diff --git a/app/views/dashboard/no_workflows.html b/app/views/dashboard/no_workflows.html new file mode 100644 index 0000000..dc7faed --- /dev/null +++ b/app/views/dashboard/no_workflows.html @@ -0,0 +1,3 @@ ++You do not belong to any workflow groups. +
\ No newline at end of file diff --git a/app/views/dashboard/nterchange_training.html b/app/views/dashboard/nterchange_training.html new file mode 100644 index 0000000..b9c0052 --- /dev/null +++ b/app/views/dashboard/nterchange_training.html @@ -0,0 +1,5 @@ ++Workflow controls the process that content takes to be published on the website. +
\ No newline at end of file diff --git a/app/views/dashboard/workflow_norecords.html b/app/views/dashboard/workflow_norecords.html new file mode 100644 index 0000000..48223b0 --- /dev/null +++ b/app/views/dashboard/workflow_norecords.html @@ -0,0 +1,3 @@ +
+
+ |
+