function update($parent) { $db = JFactory::getDBO(); if (method_exists($parent, 'extension_root')) { $sqlfile = $parent->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql'; } else { $sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql'; } // Don't modify below this line $buffer = file_get_contents($sqlfile); if ($buffer !== false) { jimport('joomla.installer.helper'); $queries = JInstallerHelper::splitSql($buffer); if (count($queries) != 0) { foreach ($queries as $query) { $query = trim($query); if ($query != '' && $query[0] != '#') { $db->setQuery($query); if (!$db->query()) { CJFunctions::throw_error(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), 1); return false; } } } } } echo '<p>' . JText::sprintf('COM_CJBLOG_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>'; }
function display($tpl = null) { JToolBarHelper::title(JText::_('COM_CJBLOG') . " <small>[" . JText::_("COM_CJBLOG_POINT_RULES") . "]</small>"); JToolBarHelper::divider(); $model = $this->getModel(); $app = JFactory::getApplication(); switch ($this->action) { case 'default': JToolBarHelper::publishList(); JToolBarHelper::unpublishList(); JToolBarHelper::deleteList(); $return = $model->get_rules(); $items = $return->rules ? $return->rules : array(); $this->assignRef('items', $items); $this->assignRef('state', $return->state); $this->assignRef('pagination', $return->pagination); $tpl = null; break; case 'form': JToolBarHelper::save(); JToolBarHelper::cancel(); $id = $app->input->getInt('id', 0); if (!$id) { return CJFunctions::throw_error(JText::_('COM_CJBLOG_NO_ITEM_FOUND'), 404); } $rule = $model->get_rule($id); $this->assignRef('rule', $rule); $tpl = 'form'; break; } parent::display($tpl); }
function get_user_points() { if (JFactory::getUser()->guest) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } else { $view = $this->getView('user', 'html'); $model = $this->getModel('users'); $view->setModel($model, true); $view->assign('action', 'user_points'); $view->display(); } }
function display($tpl = null) { $app = JFactory::getApplication(); $active = $app->getMenu()->getActive(); $cache = JFactory::getCache(); $user = JFactory::getUser(); $model = $this->getModel(); $articles_model = $this->getModel('articles'); /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(CJBLOG); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ $id = $app->input->getInt('id', 0); if (!$id) { if (!$user->guest) { $id = $user->id; } else { if ($this->params->get('blogUserId', 0) > 0) { $id = $this->params->get('blogUserId'); } else { CJFunctions::throw_error(JText::_('MSG_NO_USER_FOUND'), 403); return; } } } $limitstart = $app->input->getInt('start', 0); $limitstart = floor($limitstart / 5) * 5; $profile = $cache->call(array('CjBlogApi', 'get_user_profile'), $id); $articles = $model->get_articles(array('published' => 1, 'pagination' => true, 'limitstart' => $limitstart, 'limit' => 5, 'order' => 'a.created', 'order_dir' => 'desc', 'user_id' => $id)); $this->assignRef('user', $profile); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $document = JFactory::getDocument(); $title = JText::sprintf('TXT_USERS_BLOG', addslashes($profile['name'])); $title = CjBlogHelper::get_page_title($title); $document->setTitle($title); if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } parent::display($tpl); }
function display($tpl = null) { JToolBarHelper::title(JText::_('COM_CJBLOG') . " <small>[" . JText::_("COM_CJBLOG_BADGES") . "]</small>"); JToolBarHelper::divider(); $model = $this->getModel(); $app = JFactory::getApplication(); switch ($this->action) { case 'default': JToolBarHelper::addNew(); JToolBarHelper::editList(); JToolBarHelper::publishList(); JToolBarHelper::unpublishList(); JToolBarHelper::deleteList(); $return = $model->get_badges(); $items = $return->badges ? $return->badges : array(); $this->assignRef('items', $items); $this->assignRef('state', $return->state); $this->assignRef('pagination', $return->pagination); $tpl = null; break; case 'add': JToolBarHelper::save(); JToolBarHelper::cancel(); $components = $model->get_components(); $badge = new stdClass(); $badge->title = $badge->alias = $badge->name = $badge->description = $badge->asset_name = $badge->icon = $badge->css_class = ''; $badge->id = $badge->published = 0; $this->assignRef('components', $components); $this->assignRef('badge', $badge); $tpl = 'form'; break; case 'edit': JToolBarHelper::save(); JToolBarHelper::cancel(); if (!empty($this->badge)) { $app->enqueueMessage($model->getError()); $this->assignRef('badge', $this->badge); } else { $id = $app->input->getInt('id', 0); if (!$id) { return CJFunctions::throw_error(JText::_('COM_CJBLOG_NO_ITEM_FOUND'), 404); } $badge = $model->get_badge($id); $this->assignRef('badge', $badge); } $components = $model->get_components(); $this->assignRef('components', $components); $tpl = 'form'; break; } parent::display($tpl); }
function display($tpl = null) { $app = JFactory::getApplication(); $active = $app->getMenu()->getActive(); $cache = JFactory::getCache(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $model = $this->getModel(); $articles_model = $this->getModel('articles'); /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(CJBLOG); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ $document->addScript(CJBLOG_MEDIA_URI . 'js/jquery.form.js'); $document->addScript(CJBLOG_MEDIA_URI . 'js/jquery.Jcrop.min.js'); $id = $app->input->getInt('id', 0); if (!$id) { if (!$user->guest) { $id = $user->id; } else { CJFunctions::throw_error(JText::_('MSG_NO_USER_FOUND'), 403); return; } } if ($user->id != $id) { $model->hit($id); } $profile = $cache->call(array('CjBlogApi', 'get_user_profile'), $id); // $badges = $cache->call(array('CjBlogApi', 'get_user_badges'), $id); // $articles = $cache->call(array($articles_model, 'get_articles'), array('published'=>1, 'pagination'=>false, 'limitstart'=>0, 'limit'=>5, 'user_id'=>$id)); if (!$profile) { CJFunctions::throw_error(JText::_('MSG_NO_USER_FOUND'), 403); } $this->assignRef('profile', $profile); $document->setTitle(CjBlogHelper::get_page_title($profile['name'])); if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } parent::display($tpl); }
function display($tpl = null) { JToolBarHelper::title(JText::_('COM_CJBLOG') . " <small>[" . JText::_("COM_CJBLOG_BADGE_RULES") . "]</small>"); JToolBarHelper::divider(); $model = $this->getModel(); $app = JFactory::getApplication(); switch ($this->action) { case 'rule_list': JToolBarHelper::addNew(); JToolBarHelper::editList(); JToolBarHelper::publishList(); JToolBarHelper::unpublishList(); JToolBarHelper::deleteList(); $return = $model->get_badge_rules(); $items = !empty($return->rules) ? $return->rules : array(); $this->assignRef('items', $items); $this->assignRef('state', $return->state); $this->assignRef('pagination', $return->pagination); break; case 'rule_types': JToolBarHelper::cancel(); $rule_types = $model->get_rule_types(); $this->assignRef('rules', $rule_types); $tpl = 'rule_types'; break; case 'edit': JToolBarHelper::cancel(); JToolBarHelper::save(); $id = $app->input->getInt('id', 0); $name = $app->input->getCmd('name', null); $asset_name = $app->input->getCmd('asset', null); if ($id > 0 || !empty($name) && !empty($asset_name)) { $rule_type = $model->get_rule_type($id, $asset_name, $name); if (empty($rule_type)) { return CJFunctions::throw_error(JText::_('COM_CJBLOG_ERROR_PROCESSING'), 404); } $this->assignRef('rule_type', $rule_type); } else { return CJFunctions::throw_error(JText::_('COM_CJBLOG_NO_ITEM_FOUND'), 404); } $tpl = 'rule_form'; break; } parent::display($tpl); }
function get_article_form() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $view = $this->getView('form', 'html'); $model = $this->getModel('articles'); $id = $app->input->getInt('id', 0); if ($id > 0) { $asset = 'com_content.article.' . $id; if (!$user->authorise('core.edit', $asset) && !$user->authorise('core.edit.own', $asset)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); return false; } jimport('joomla.database.table'); JTable::addIncludePath(JPATH_PLATFORM . DS . 'joomla' . DS . 'database' . DS . 'table' . DS); $row = JTable::getInstance('content'); if (!$row || !$row->load($id)) { CJFunctions::throw_error($row->getError(), 403); } if (!$row->checkout($user->id)) { return CJFunctions::throw_error($row->getError(), 403); } else { $this->holdEditId('com_content.edit.article', $id); } } else { if ($user->guest) { $itemid = CJFunctions::get_active_menu_id(); $form_itemid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . CJBLOG . '&view=form'); $redirect = base64_encode(JRoute::_('index.php?option=' . CJBLOG . '&view=form' . $form_itemid)); $this->setRedirect(JRoute::_('index.php?option=com_users&view=login' . $itemid . '&return=' . $redirect, false), JText::_('COM_CJBLOG_USER_LOGIN')); return false; } else { if (!$user->authorise('core.create', 'com_content')) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); return false; } } } $view->setModel($model, true); $view->assign('action', 'form'); $view->display(); }
public static function get_config($rebuild = false) { $app = JFactory::getApplication(); $config = $app->getUserState(BLOG_SESSION_CONFIG); if (empty($config) || $rebuild) { $db = JFactory::getDBO(); $query = 'SELECT config_name, config_value FROM ' . T_CJBLOG_CONFIG; $db->setQuery($query); $configt = $db->loadObjectList(); if ($configt) { foreach ($configt as $ct) { $config[$ct->config_name] = $ct->config_value; } } else { return CJFunctions::throw_error(JText::_('MSG_UNAUTHORISED') . ' Error code: 10001.', 403); } $app->setUserState(BLOG_SESSION_CONFIG, $config); } return $config; }
function get_all_surveys() { $user = JFactory::getUser(); if ($user->guest) { $itemid = CJFunctions::get_active_menu_id(); $redirect_url = base64_encode(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=all' . $itemid)); $this->setRedirect(CJFunctions::get_login_url($redirect_url, $itemid), JText::_('MSG_NOT_LOGGED_IN')); } else { if ($user->authorise('core.manage', S_APP_NAME)) { $view = $this->getView('survey', 'html'); $model = $this->getModel('survey'); $users_model = $this->getModel('users'); $categories_model = $this->getModel('categories'); $view->setModel($model, true); $view->setModel($users_model, false); $view->setModel($categories_model, false); $view->assign('action', 'all_surveys'); $view->display(); } else { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } } }
function display($tpl = null) { $app = JFactory::getApplication(); $cache = JFactory::getCache(); $active = $app->getMenu()->getActive(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $pathway = $app->getPathway(); $model = $this->getModel(); $category_model = $this->getModel('categories'); $limit = $app->getCfg('list_limit', 20); $limitstart = $app->input->getInt('limitstart', 0); $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0; $this->print = $app->input->getBool('print'); $catid = $app->input->getInt('id', 0); $this->category = $category = null; $max_cat_levels = 0; $page_heading = ''; $page_url = 'index.php?option=' . CJBLOG . '&view=articles'; /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(CJBLOG); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); $active_menu_catid = (int) $menuParams->get('catid', 0); if ($catid == 0 && $active_menu_catid > 0) { $catid = $active_menu_catid; } } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ if ($this->action != 'tagged_articles' && $catid > 0) { $max_cat_levels = intval($this->params->get('max_category_levels', -1)); $category = $category_model->get_category($catid); $groups = $user->getAuthorisedViewLevels(); if (!$category || !in_array($category->access, $groups)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $this->assignRef('category', $category); $app->input->set('cjblogcatid', $catid); } switch ($this->action) { case 'latest_articles': $articles = $model->get_articles(array('published' => 1, 'pagination' => true, 'limitstart' => $limitstart, 'limit' => $limit, 'catid' => $catid, 'max_cat_levels' => $max_cat_levels, 'order' => 'a.created', 'order_dir' => 'desc')); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $this->assign('active_id', 3); $page_heading = JText::_('LBL_LATEST_ARTICLES'); $page_url = $page_url . '&task=latest'; break; case 'trending_articles': $trending_days = 30; $articles = $model->get_articles(array('published' => 1, 'pagination' => true, 'day_limit' => $trending_days, 'limitstart' => $limitstart, 'limit' => $limit, 'catid' => $catid, 'max_cat_levels' => $max_cat_levels, 'order' => 'a.hits', 'order_dir' => 'desc')); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $this->assign('active_id', 3); $page_heading = JText::_('LBL_TRENDING_ARTICLES') . ' ( ' . JText::sprintf('TXT_IN_LAST_X_DAYS', $trending_days) . ' )'; $page_url = $page_url . '&task=trending'; break; case 'popular_articles': $articles = $model->get_articles(array('published' => 1, 'pagination' => true, 'limitstart' => $limitstart, 'limit' => $limit, 'catid' => $catid, 'max_cat_levels' => $max_cat_levels, 'order' => 'a.hits', 'order_dir' => 'desc')); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $this->assign('active_id', 3); $page_heading = JText::_('LBL_MOST_POPULAR_ARTICLES'); $page_url = $page_url . '&task=popular'; break; case 'favorite_articles': $articles = $model->get_articles(array('published' => 1, 'pagination' => true, 'limitstart' => $limitstart, 'limit' => $limit, 'catid' => $catid, 'favorites' => true, 'max_cat_levels' => $max_cat_levels, 'order' => 'a.hits', 'order_dir' => 'desc')); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $this->assign('active_id', 6); $page_heading = JText::_('LBL_MY_FAVORITE_ARTICLES'); $page_url = $page_url . '&task=favorites'; break; case 'tagged_articles': $id = $app->input->getInt('id', 0); if (!$id) { return CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $articles = $model->get_articles(array('tag_id' => $id, 'published' => 1, 'pagination' => true, 'limitstart' => $limitstart, 'limit' => $limit, 'max_cat_levels' => $max_cat_levels, 'order' => 'a.created', 'order_dir' => 'desc')); $tag = $model->get_tag_details($id); $this->assignRef('articles', $articles->articles); $this->assignRef('pagination', $articles->pagination); $this->assign('page_description', $tag->description); $this->assign('active_id', 3); $page_heading = JText::sprintf('TXT_TAGGED_ARTICLES', $this->escape($tag->tag_text)); $page_url = $page_url . '&task=tag&id=' . $tag->id . ':' . $tag->alias; break; } // set breadcrumbs $path = array(array('title' => $this->params->get('page_heading'), 'link' => '')); if ($category) { $temp = $category; $page_heading = $page_heading . ': ' . $category->title; $page_url = $page_url . '&id=' . $category->id . (!empty($category->alias) ? ':' . $category->alias : ''); while ($temp && ($active->query['option'] != CJBLOG || $active->query['view'] == 'articles') && $temp->id > 1) { $path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($temp->id)); $temp = $temp->getParent(); } } $path = array_reverse($path); foreach ($path as $item) { $pathway->addItem($item['title'], $item['link']); } // set browser title $this->params->set('page_heading', $this->params->get('page_heading', $page_heading)); $title = $this->params->get('page_title', ''); if (empty($title)) { $title = $page_heading; } $document->setTitle(CjBlogHelper::get_page_title($title)); // set meta description if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } // set meta keywords if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } // set robots if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } // set nofollow if it is print if ($this->print) { $document->setMetaData('robots', 'noindex, nofollow'); } $this->assignRef('page_url', $page_url); // display parent::display($tpl); }
function display($tpl = null) { $app = JFactory::getApplication(); $model = $this->getModel(); $document = JFactory::getDocument(); $user = JFactory::getUser(); $pathway = $app->getPathway(); $active = $app->getMenu()->getActive(); $itemid = CJFunctions::get_active_menu_id(); $this->print = $app->input->getBool('print'); $page_heading = ''; /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(S_APP_NAME); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ switch ($this->action) { case 'survey_intro': $page_heading = JText::sprintf('TXT_INTRODUCTION', $this->escape($this->item->title)); break; case 'response_form': $page_heading = JText::sprintf('TXT_SURVEY_RESPONSE', $this->escape($this->item->title)); break; case 'survey_results': $id = $app->input->getInt('id', 0); $response_id = $app->input->getInt('rid', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_consolidated_report($id); if (empty($survey) || $survey->public_permissions != 1 && $survey->created_by != $user->id && !$user->authorise('core.manage', 'com_communitysurveys')) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $response_details = $model->get_response_details($response_id, $id, 0, true, true); if (!empty($response_details) && !empty($survey->questions)) { foreach ($response_details as $response_detail) { foreach ($survey->questions as &$question) { if ($question->id == $response_detail->question_id) { $question->response_details[] = $response_detail; } } } } $page_heading = JText::sprintf('TXT_RESULTS', $this->escape($survey->title)); $this->assignRef('item', $survey); $this->assign('responseId', $response_id); break; case 'end_message': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id); if (isset($survey->catid) && !$user->authorise('core.respond', S_APP_NAME . '.category.' . $survey->catid)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); return; } if ($survey->private_survey != '1' && $this->params->get('enable_related_surveys', 1) == 1) { $search_params = array('q' => $survey->title, 'u' => '', 'qt' => 0, 'm' => 0, 'type' => 0, 'all' => 0); $options = array('catid' => 0, 'search_params' => $search_params, 'limit' => 5, 'limitstart' => 0, 'order' => 'a.created', 'order_dir' => 'desc'); $return = $model->get_surveys(7, $options, $this->params); $survey->related = $return['surveys']; } else { $survey->related = array(); } $page_heading = JText::sprintf('TXT_RESULTS', $this->escape($survey->title)); $this->assignRef('item', $survey); break; } if ($this->is_hide_template($this->params->get('hide_template', 0), $this->item->display_template)) { $app->input->set('tmpl', 'component'); $app->input->set('format', 'raw'); CJLib::import('corejoomla.ui.bootstrap', true); $this->assign('hide_template', 1); } else { $this->assign('hide_template', 0); } $this->assign('brand', JText::_('LBL_HOME')); $this->assign('brand_url', 'index.php?option=' . S_APP_NAME . '&view=survey' . $itemid); // set browser title $this->params->set('page_heading', $this->params->get('page_heading', $page_heading)); $pathway->addItem($page_heading); $title = $this->params->get('page_title', $app->getCfg('sitename')); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $document->setTitle(JText::sprintf('JPAGETITLE', $title, $page_heading)); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $document->setTitle(JText::sprintf('JPAGETITLE', $page_heading, $title)); } else { $document->setTitle($page_heading); } // set meta description if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } // set meta keywords if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } // set robots if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } // set nofollow if it is print if ($this->print) { $document->setMetaData('robots', 'noindex, nofollow'); } parent::display($tpl); }
function copy_survey() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = JModelLegacy::getInstance('survey', 'CommunitySurveysModel'); $id = $app->input->getInt('id', 0); if (!$id) { $this->setRedirect('index.php?option=' . S_APP_NAME . '&view=surveys', JText::_('MSG_ERROR_PROCESSING')); } if (!$user->authorise('core.create', S_APP_NAME) && !$user->authorise('core.manage', S_APP_NAME)) { return CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 403); } else { if (!$model->copy_survey($id)) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys'), JText::_('MSG_ERROR_PROCESSING')); } else { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=surveys'), JText::_('MSG_COPY_SUCCESS')); } } }
function copy_surveys() { $app = JFactory::getApplication(); $ids = $app->input->post->getArray(array('cid' => 'array')); if (count($ids['cid']) == 0) { $this->setRedirect('index.php?option=' . S_APP_NAME . '&view=surveys', JText::_('COM_COMMUNITYSURVEYS_MSG_INVALID_ID')); } if (!JFactory::getUser()->authorise('core.create', S_APP_NAME)) { return CJFunctions::throw_error(JText::_('COM_COMMUNITYSURVEYS_NOT_AUTHORIZED'), 403); } else { JArrayHelper::toInteger($ids['cid']); $model = JModelLegacy::getInstance('survey', 'CommunitySurveysModel'); foreach ($ids['cid'] as $cid) { if (!$model->copy_survey($cid)) { foreach ($model->getErrors() as $error) { $app->enqueueMessage($error, 'error'); } } } $this->setRedirect('index.php?option=' . S_APP_NAME . '&view=surveys', JText::_('COM_COMMUNITYSURVEYS_MSG_SUCCESS')); } }
public function download_consolidated_pdf_report() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $model = $this->getModel('survey'); $params = JComponentHelper::getParams(S_APP_NAME); $id = $app->input->getInt('id', 0); if (!$id || !$model->authorize_survey($id)) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $wysiwyg = $user->authorise('core.wysiwyg', S_APP_NAME) ? true : false; $bbcode = $wysiwyg && $params->get('default_editor', 'bbcode') == 'bbcode'; $content = $params->get('process_content_plugins', 0) == 1; require_once JPATH_COMPONENT . '/helpers/reports.php'; $generator = new SurveyReports($wysiwyg, $bbcode, $content); $survey = $model->get_consolidated_report($id); $headStyles = array(); $headStyles[] = CJLIB_URI . '/bootstrap/css/bootstrap.min.css'; $headStyles[] = JURI::root(true) . '/media/' . S_APP_NAME . '/css/cj.surveys.min.css'; $headScripts = array(); $headScripts[] = CJLIB_URI . '/jquery/jquery.min.js'; $headScripts[] = CJLIB_URI . '/jquery/jquery.noconflict.js'; $headScripts[] = CJLIB_URI . '/bootstrap/js/bootstrap.min.js'; $headScripts[] = 'https://www.google.com/jsapi'; $headScripts[] = JURI::root(true) . '/media/' . S_APP_NAME . '/js/cj.surveys.min.js'; $html = '<html xmlns="http://www.w3.org/1999/xhtml" dir="' . JFactory::getDocument()->direction . '"><head>'; $html = $html . '<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; // foreach ($headStyles as $style) // { // $html = $html . '<link rel="stylesheet" href="'.$style.'" type="text/css" />'; // } // foreach ($headScripts as $script) // { // $html = $html . '<script src="'.$script.'" type="text/javascript"></script>'; // } // $html .= '<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(SurveyFactory.draw_consolidated_charts);</script>'; $html .= '</head><body><div id="cj-wrapper" class="container-fuild"><div class="reports-wrapper margin-top-20">'; $html .= '<h2 class="page-header margin-bottom-10">' . CJFunctions::escape($survey->title) . '</h2>'; foreach ($survey->questions as $item) { switch ($item->question_type) { case 1: $html .= $generator->get_page_header_question($item, ''); break; case 2: case 3: case 4: case 11: case 12: $html .= $generator->get_choice_question($item, ''); break; case 5: case 6: $html .= $generator->get_grid_question($item, ''); break; } } $html .= '</div></div></body></html>'; // All validations done, write data now $fileName = 'survey_' . $id . '_' . date('dmYHis') . '.pdf'; // create new PDF document require_once JPATH_COMPONENT_SITE . '/helpers/tcpdf.php'; $pdf = new MYPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set default header data $pdf->SetHeaderData('logo.png', PDF_HEADER_LOGO_WIDTH, $survey->title, ''); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('corejoomla.com'); $pdf->SetTitle('Survey Report'); $pdf->SetSubject('Consolidated Report'); $pdf->SetKeywords('survey, report'); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- // set font $pdf->SetFont('freesans'); $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->lastPage(); $pdf->Output($fileName, $mode); jexit(); } }
function get_os_report() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $model = $this->getModel('survey'); $id = $app->input->getInt('id', 0); if (!$id || !$model->authorize_survey($id)) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $view = $this->getView('reports', 'html'); $view->setModel($model, true); $view->assign('action', 'os_report'); $view->display('oses'); } }
public function view_result() { $user = JFactory::getUser(); if (!$user->authorise('core.results', S_APP_NAME)) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $view = $this->getView('response', 'html'); $model = $this->getModel('survey'); $view->setModel($model, true); $view->assign('action', 'survey_results'); $view->display('result'); } }
function save_response($sid, $pid, $rid, $ignore_error = false, $skip_validations = false) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $questions = $this->get_questions($sid, $pid); $config = JComponentHelper::getParams(S_APP_NAME); $html_allowed = $user->authorise('core.wysiwyg', S_APP_NAME) && $config->get('default_editor', 'bbcode') == 'wysiwyg'; // validate if legimate user if (!$user->guest && !$user->authorise('core.manage', S_APP_NAME)) { $query = 'select created_by from #__survey_responses where id = ' . $rid; $this->_db->setQuery($query); $created_by = (int) $this->_db->loadResult(); if ($created_by > 0 && $created_by != $user->id) { if (!$ignore_error) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $this->setError(JText::_('MSG_UNAUTHORIZED') . '| Error: 1'); } return false; } } $rules = $this->get_conditional_rules($sid, $pid, null, true); $return = new stdClass(); $return->page_id = $return->finalize = 0; if (!empty($questions)) { $answers = array(); foreach ($questions as $question) { $free_text = null; switch ($question->question_type) { case 2: // Choice - Radio // Choice - Radio case 4: // Choice - Select box // Choice - Select box case 11: // Image - Radio $answer_id = $app->input->post->getInt('answer-' . $question->id, 0); $free_text = $app->input->post->getString('free-text-' . $question->id, null); if ($answer_id) { $answer = array(); $answer['question_id'] = $question->id; $answer['answer_id'] = $answer_id; $answer['column_id'] = 0; $answer['free_text'] = null; array_push($answers, $answer); } if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $this->validate_rules($question->id, array($answer_id), $rules, $return, 1); } break; case 3: // Choice - Checkbox // Choice - Checkbox case 12: // Image - Checkbox $answer_ids = $app->input->post->getArray(array('answer-' . $question->id => 'array')); $free_text = $app->input->post->getString('free-text-' . $question->id, null); $answer_ids = $answer_ids['answer-' . $question->id]; JArrayHelper::toInteger($answer_ids); if (!empty($answer_ids)) { foreach ($answer_ids as $answer_id) { $answer = array(); $answer['question_id'] = $question->id; $answer['answer_id'] = $answer_id; $answer['column_id'] = 0; $answer['free_text'] = null; array_push($answers, $answer); } } if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $this->validate_rules($question->id, $answer_ids, $rules, $return, 1); } break; case 5: // Grid - Radio $rows = array(); $columns = array(); $grid_answers = array(); foreach ($question->answers as $answer) { if ($answer->answer_type == 'x') { $rows[] = $answer; } else { if ($answer->answer_type == 'y') { $columns[] = $answer; } } } $free_text = $app->input->post->getString('free-text-' . $question->id, null); foreach ($rows as $row) { $column_id = $app->input->post->getInt('answer-' . $question->id . '-' . $row->id, 0); if ($column_id) { $answer = array(); $answer['question_id'] = $question->id; $answer['answer_id'] = $row->id; $answer['column_id'] = $column_id; $answer['free_text'] = null; array_push($grid_answers, array($row->id => $column_id)); array_push($answers, $answer); } } if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $this->validate_rules($question->id, $grid_answers, $rules, $return, 2); } break; case 6: // Grid - Checkbox $rows = array(); $columns = array(); $grid_answers = array(); foreach ($question->answers as $answer) { if ($answer->answer_type == 'x') { $rows[] = $answer; } else { if ($answer->answer_type == 'y') { $columns[] = $answer; } } } $free_text = $app->input->post->getString('free-text-' . $question->id, null); foreach ($rows as $row) { $column_ids = $app->input->post->getArray(array('answer-' . $question->id . '-' . $row->id => 'array')); $column_ids = $column_ids['answer-' . $question->id . '-' . $row->id]; JArrayHelper::toInteger($column_ids); if (!empty($column_ids)) { foreach ($column_ids as $column_id) { $answer = array(); $answer['question_id'] = $question->id; $answer['answer_id'] = $row->id; $answer['column_id'] = $column_id; $answer['free_text'] = null; array_push($grid_answers, array($row->id => $column_id)); array_push($answers, $answer); } } } if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $this->validate_rules($question->id, $grid_answers, $rules, $return, 2); } break; case 7: // Freetext - Singleline // Freetext - Singleline case 8: // Freetext - Multiline // Freetext - Multiline case 9: // Freetext - Password // Freetext - Password case 14: // Special - Email // Special - Email case 15: // Special - Calendar $free_text = $app->input->post->getString('free-text-' . $question->id, null); if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $this->validate_rules($question->id, array($free_text), $rules, $return, 3); } break; case 10: // Freetext - Rich text $free_text = CJFunctions::get_clean_var('free-text-' . $question->id, $html_allowed); if (!empty($rules) && empty($return->finalize) && empty($return->page_id)) { $text = strip_tags($free_text); $this->validate_rules($question->id, array($text), $rules, $return, 3); } break; case 13: // Special - Name $names = $app->input->getArray(array('user-name-' . $question->id => 'array')); if (count($names['user-name-' . $question->id]) == 3) { $free_text = implode('|', $names['user-name-' . $question->id]); $tmp_text = str_replace('|', '', $free_text); if (empty($tmp_text)) { $free_text = ''; } $this->validate_rules($question->id, array($free_text), $rules, $return, 3); } break; case 16: // Special - Address $addr_name = $app->input->post->getString('address-name-' . $question->id, ''); $addr_line1 = $app->input->post->getString('address-line1-' . $question->id, ''); $addr_line2 = $app->input->post->getString('address-line2-' . $question->id, ''); $addr_city = $app->input->post->getString('address-city-' . $question->id, ''); $addr_state = $app->input->post->getString('address-state-' . $question->id, ''); $addr_country = $app->input->post->getString('address-country-' . $question->id, ''); $addr_zip = $app->input->post->getString('address-zip-' . $question->id, ''); if (!empty($addr_name) && !empty($addr_line1) && !empty($addr_city) && !empty($addr_state) && !empty($addr_country) && !empty($addr_zip)) { $free_text = $addr_name . '|||' . $addr_line1 . '|||' . $addr_line2 . '|||' . $addr_city . '|||' . $addr_state . '|||' . $addr_country . '|||' . $addr_zip; } break; } if ($free_text) { $answer = array(); $answer['question_id'] = $question->id; $answer['answer_id'] = 0; $answer['column_id'] = 0; $answer['free_text'] = $free_text; array_push($answers, $answer); } } $query = ' delete from #__survey_response_details where response_id=' . $rid . ' and question_id in (select id from #__survey_questions where survey_id=' . $sid . ' and page_number=' . $pid . ')'; $this->_db->setQuery($query); if ($this->_db->query()) { $query = ''; foreach ($answers as $answer) { if (empty($answer['free_text'])) { $answer['free_text'] = 'null'; } else { $answer['free_text'] = $this->_db->quote($answer['free_text']); } $query = $query . '(' . $rid . ',' . $answer['question_id'] . ',' . $answer['answer_id'] . ',' . $answer['column_id'] . ',' . $answer['free_text'] . '),'; } if (!empty($query)) { $query = 'insert into #__survey_response_details (response_id, question_id, answer_id, column_id, free_text) values ' . $query; $query = substr($query, 0, -1); $this->_db->setQuery($query); if ($this->_db->query()) { return $return; } } else { return $return; } } } $this->setError($this->_db->getErrorMsg()); return false; }
function unpublish_article() { $user = JFactory::getUser(); if (!$user->authorise('core.edit.state')) { return CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } else { $app = JFactory::getApplication(); $model = $this->getModel('articles'); $id = $app->input->getInt('id'); $return = $app->input->getBase64('return', null); if (empty($return) || !JUri::isInternal(base64_decode($return))) { $return = JURI::base(); } else { $return = base64_decode($return); } if ($model->publish_article($id, 2)) { $this->setRedirect($return, JText::_('MSG_ARTICLE_PUBLISHING_SUCCESS')); } else { $this->setRedirect($return, JText::_('MSG_ERROR_PROCESSING')); } } }
} // require helper file JLoader::register('CommunitySurveysHelper', dirname(__FILE__) . '/helpers/communitysurveys.php'); $task = $app->input->getCmd('task'); if (strpos($task, '.') !== false) { $controller = JControllerLegacy::getInstance('CommunitySurveys'); $controller->execute($task); $controller->redirect(); } else { /********************************* MAIN CONTENT ***********************************************/ CJLib::import('corejoomla.ui.bootstrap'); $view = $app->input->getCmd('view', 'dashboard'); if (JFile::exists(JPATH_COMPONENT . DS . 'controllers' . DS . $view . '.php')) { require_once JPATH_COMPONENT . DS . 'controllers' . DS . $view . '.php'; } else { CJFunctions::throw_error('View ' . JString::ucfirst($view) . ' not found!', 500); } $classname = 'CommunitySurveysController' . JString::ucfirst($view); $controller = new $classname(); $document = JFactory::getDocument(); CJFunctions::load_jquery(array('libs' => array('fontawesome'))); $document->addStyleSheet(CJLIB_URI . '/framework/assets/cj.framework.css'); $document->addStyleSheet(JURI::base(true) . '/components/' . S_APP_NAME . '/assets/css/cj.surveys.admin.min.css'); $document->addScript(JURI::base(true) . '/components/' . S_APP_NAME . '/assets/js/cj.surveys.admin.min.js'); CommunitySurveysHelper::addSubmenu($view); $params = JComponentHelper::getParams(S_APP_NAME); define('S_DEBUG_ENABLED', $params->get('enable_debugging', 0) == '1'); /********************************* VERSION CHECK *******************************/ if (empty($task)) { $version = $app->getUserState(S_APP_NAME . '.VERSION'); if (!$version) {
function display($tpl = null) { $app = JFactory::getApplication(); $model = $this->getModel(); $document = JFactory::getDocument(); $user = JFactory::getUser(); $active = $app->getMenu()->getActive(); $itemid = CJFunctions::get_active_menu_id(); $this->print = $app->input->getBool('print'); $page_heading = ''; /********************************** PARAMS *****************************/ $this->params = JComponentHelper::getParams(S_APP_NAME); /********************************** PARAMS *****************************/ CJFunctions::load_jquery(array('libs' => array('fontawesome'))); $document->addScript(JUri::root(true) . '/media/' . S_APP_NAME . '/js/cj.surveys.min.js'); $document->addStyleDeclaration('#element-box .m {background-color: #fff;}'); JToolBarHelper::custom('surveys', 'back', 'back', JText::_('COM_COMMUNITYSURVEYS_SURVEYS'), false, false); switch ($this->action) { case 'survey_reports': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey->stats = $model->get_survey_statistics($survey->id); $this->assignRef('item', $survey); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'consolidated_report': $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($this->item->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); break; case 'survey_responses': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_responses($survey->id, 0, 'limitstart'); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('responses', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); JToolBarHelper::custom('csvdownload', 'download', 'download', 'CSV', false, false); JToolBarHelper::custom('pdfdownload', 'download', 'download', 'PDF', true, false); JToolBarHelper::divider(); JToolBarHelper::deleteList('', 'remove_responses', 'JTOOLBAR_DELETE'); break; case 'location_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_location_report($survey->id, 'limitstart'); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('locations', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); break; case 'device_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_device_report($survey->id, 'limitstart'); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('devices', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); break; case 'os_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_os_report($survey->id, 'limitstart'); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('oses', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); break; case 'view_response': $id = $app->input->getInt('id', 0); $rid = $app->input->getInt('rid', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey->questions = $model->get_questions($survey->id); $responses = $model->get_response_details($rid, $survey->id, 0, false); foreach ($survey->questions as &$question) { $question->responses = array(); foreach ($responses as $response) { if ($question->id == $response->question_id) { $question->responses[] = $response; } } } $page_heading = JText::sprintf('TXT_RESULTS', $this->escape($survey->title)); JToolBarHelper::custom('reports', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_REPORTS'), false, false); JToolBarHelper::custom('responses', 'picture', 'picture', JText::_('COM_COMMUNITYSURVEYS_RESPONSES'), false, false); $this->assignRef('item', $survey); $this->assign('response_id', $rid); break; } $this->assign('brand', JText::_('LBL_HOME')); $this->assign('brand_url', 'index.php?option=' . S_APP_NAME . '&view=survey' . $itemid); // set browser title $this->params->set('page_heading', $this->params->get('page_heading', $page_heading)); $title = $this->params->get('page_title', $app->getCfg('sitename')); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $document->setTitle(JText::sprintf('JPAGETITLE', $title, $page_heading)); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $document->setTitle(JText::sprintf('JPAGETITLE', $page_heading, $title)); } else { $document->setTitle($page_heading); } // set meta description if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } // set meta keywords if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } // set robots if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } // set nofollow if it is print if ($this->print) { $document->setMetaData('robots', 'noindex, nofollow'); } JToolBarHelper::title(JText::_('COM_COMMUNITYSURVEYS') . ': <small><small>[ ' . JText::_('COM_COMMUNITYSURVEYS_REPORTS') . ' ]</small></small>', 'logo.png'); parent::display($tpl); }
function copy_survey() { $app = JFactory::getApplication(); $id = $app->input->getInt('id', 0); $model = $this->getModel('survey'); if (!$id) { $this->setRedirect('index.php?option=' . S_APP_NAME . '&view=surveys', JText::_('MSG_ERROR_PROCESSING')); } if (!JFactory::getUser()->authorise('core.create', S_APP_NAME) || !$model->authorize_survey($id)) { return CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 403); } else { $user_itemid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . S_APP_NAME . '&view=user'); if (!$model->copy_survey($id)) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=user&task=my_surveys' . $user_itemid), JText::_('MSG_ERROR_PROCESSING')); } else { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=user&task=my_surveys' . $user_itemid), JText::_('MSG_COPY_SUCCESS')); } } }
function display($tpl = null) { $app = JFactory::getApplication(); $model = $this->getModel(); $document = JFactory::getDocument(); $user = JFactory::getUser(); $pathway = $app->getPathway(); $active = $app->getMenu()->getActive(); $itemid = CJFunctions::get_active_menu_id(); $this->print = $app->input->getBool('print'); $page_heading = ''; /********************************** PARAMS *****************************/ $appparams = JComponentHelper::getParams(S_APP_NAME); $menuParams = new JRegistry(); if ($active) { $menuParams->loadString($active->params); } $this->params = clone $menuParams; $this->params->merge($appparams); /********************************** PARAMS *****************************/ CJFunctions::load_jquery(array('libs' => array('fontawesome'))); switch ($this->action) { case 'survey_reports': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey->stats = $model->get_survey_statistics($survey->id); $this->assignRef('item', $survey); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'consolidated_report': $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($this->item->title)); break; case 'consolidated_pdf_report': $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($this->item->title)); break; case 'survey_responses': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_responses($survey->id); $responses = empty($result->rows) ? array() : $result->rows; $this->load_users($responses); $this->assignRef('item', $survey); $this->assignRef('responses', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'location_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_location_report($survey->id); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('locations', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'device_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_device_report($survey->id); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('devices', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'os_report': $id = $app->input->getInt('id', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $result = $model->get_os_report($survey->id); $responses = empty($result->rows) ? array() : $result->rows; $this->assignRef('item', $survey); $this->assignRef('oses', $responses); $this->assignRef('pagination', $result->pagination); $this->assignRef('lists', $result->lists); $page_heading = JText::sprintf('TXT_REPORTS', $this->escape($survey->title)); break; case 'view_response': $id = $app->input->getInt('id', 0); $rid = $app->input->getInt('rid', 0); if (!$id) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey = $model->get_survey_details($id, false, true); if (empty($survey)) { CJFunctions::throw_error(JText::_('JERROR_ALERTNOAUTHOR'), 401); } $survey->questions = $model->get_questions($survey->id); $survey->response = $model->get_response_details($rid, $survey->id, 0, false, false); foreach ($survey->questions as &$question) { $question->responses = array(); foreach ($survey->response->answers as $answer) { if ($question->id == $answer->question_id) { $question->responses[] = $answer; } } } $page_heading = JText::sprintf('TXT_RESULTS', $this->escape($survey->title)); $this->assignRef('item', $survey); $this->assign('response_id', $rid); break; } $this->assign('brand', JText::_('LBL_HOME')); $this->assign('brand_url', 'index.php?option=' . S_APP_NAME . '&view=survey' . $itemid); // set browser title $this->params->set('page_heading', $this->params->get('page_heading', $page_heading)); $pathway->addItem($page_heading); $title = $this->params->get('page_title', $app->getCfg('sitename')); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $document->setTitle(JText::sprintf('JPAGETITLE', $title, $page_heading)); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $document->setTitle(JText::sprintf('JPAGETITLE', $page_heading, $title)); } else { $document->setTitle($page_heading); } // set meta description if ($this->params->get('menu-meta_description')) { $document->setDescription($this->params->get('menu-meta_description')); } // set meta keywords if ($this->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } // set robots if ($this->params->get('robots')) { $document->setMetadata('robots', $this->params->get('robots')); } // set nofollow if it is print if ($this->print) { $document->setMetaData('robots', 'noindex, nofollow'); } parent::display($tpl); }