/**
  * CP Values view display method
  * @return void
  **/
 function display($tpl = null)
 {
     global $option;
     $this->_context = $option . 'tags';
     // nombre del contexto
     $this->cid = JRequest::getVar('cid', 0, '', 'int');
     $document = JFactory::getDocument();
     $script = JUri::root() . '/administrator/components/com_customproperties/includes/customproperties_ext.js';
     $document->addScript($script);
     $app =& JFactory::getApplication();
     $user = JFactory::getUser();
     $aid = $user->get('aid', 0);
     $gid = $user->get('gid', 0);
     $ce_file = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_customproperties' . DS . 'contentelement.class.php';
     require_once $ce_file;
     // get the content element
     $option = JRequest::getVar('contentname');
     if (!$option) {
         $ce = getContentElementByName("content");
     } else {
         $ce = getContentElementByOption($option);
     }
     $this->assignRef('ce', $ce);
     $query = "  SELECT DISTINCT f.id AS fid, f.label AS name, v.id AS vid, v.label, v.access_group AS ag\r\n                    FROM #__custom_properties AS cp\r\n\t\t\tINNER JOIN #__custom_properties_fields AS f\r\n\t\t\tON (cp.field_id = f.id)\r\n\t\t\tINNER JOIN #__custom_properties_values AS v\r\n\t\t\tON (cp.value_id = v.id)\r\n                    WHERE cp.ref_table = '" . $ce->table . "'\r\n\t\t\tAND cp.content_id = '{$this->cid}'\r\n\t\t\tAND f.published = '1'\r\n\t\t\tAND f.access <= '{$aid}'\r\n                    ORDER BY f.ordering, v.ordering ";
     $database = JFactory::getDBO();
     $database->setQuery($query);
     $database->getErrorMsg();
     $this->assignRef('tags', $database->loadObjectList());
     $this->assignRef('app', $app);
     $this->assignRef('gid', $gid);
     parent::display($tpl);
 }
 /**
  * CP Fields assign method
  * @return void
  **/
 function display($tpl = null)
 {
     // content element
     $ce_name = JRequest::getVar('ce_name', null, '', 'string');
     if (!($content_element = getContentElementByName("{$ce_name}"))) {
         $content_element = getContentElementByName("content");
         $ce_name = 'content';
     }
     // content items
     $content = $this->getModel('content', 'custompropertiesModel');
     $items = $content->getList($content_element);
     $page = $content->getPagination($content_element);
     // CP fields
     $cp = $this->getModel('cpfields', 'custompropertiesModel');
     $cpfields = $cp->getList(false);
     // properties
     $assign =& $this->getModel();
     $content_id = $assign->_id;
     $item_title = $assign->getTitle();
     $this->assignRef('items', $items);
     $this->assignRef('page', $page);
     $this->assignRef('content_element', $content_element);
     $this->assignRef('ce_name', $ce_name);
     $this->assignRef('cpfields', $cpfields);
     $this->assignRef('content_id', $content_id);
     $this->assignRef('item_title', $item_title);
     parent::display($tpl);
 }
 /**
  * Constructor that retrieves the ID from the request
  *
  * @access    public
  * @return    void
  */
 function __construct()
 {
     parent::__construct();
     if ($content_id = JRequest::getVar('cid', null, '', 'array')) {
         $this->setId((int) $content_id[0]);
     } elseif ($content_id = JRequest::getVar('id', null)) {
         $this->setId($content_id);
     } else {
         return false;
     }
     $ce_name = JRequest::getVar('ce_name', null);
     if (!($content_element = getContentElementByName("{$ce_name}"))) {
         $content_element = getContentElementByName("content");
     }
     $this->setContentElement($content_element);
 }
 /**
  * CP Fields assign method
  * @return void
  **/
 function display($tpl = null)
 {
     // content element
     $ce_name = JRequest::getVar('ce_name', null, '', 'string');
     if (!empty($ce_name)) {
         if (!($content_element = getContentElementByName("{$ce_name}", true))) {
             $content_element = getContentElementByName("content", true);
             $ce_name = 'content';
         }
     } else {
         $content_elements = getInstalledContentElements();
         if (count($content_elements) > 0) {
             //return the first CE available
             $content_element = current($content_elements);
             $ce_name = $content_element->name;
         } else {
             $content_element = getDefaultContentElement();
             $ce_name = $content_element->name;
         }
     }
     // content items
     $content = $this->getModel('content', 'custompropertiesModel');
     $items = $content->getList($content_element);
     $page = $content->getPagination($content_element);
     // CP fields
     $cp = $this->getModel('cpfields', 'custompropertiesModel');
     $cpfields = $cp->getList(false);
     // properties
     $assign =& $this->getModel();
     $content_id = $assign->_id;
     $item_title = $assign->getTitle();
     $this->assignRef('items', $items);
     $this->assignRef('page', $page);
     $this->assignRef('content_element', $content_element);
     $this->assignRef('ce_name', $ce_name);
     $this->assignRef('cpfields', $cpfields);
     $this->assignRef('content_id', $content_id);
     $this->assignRef('item_title', $item_title);
     parent::display($tpl);
 }
 /**
  * CP Fields assign method
  * @return void
  **/
 function display($tpl = null)
 {
     global $mainframe, $cp_config;
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'cp_config.php';
     // content element
     $ce_name = JRequest::getVar('ce_name', null, '', 'string');
     if (!($content_element = getContentElementByName("{$ce_name}"))) {
         $content_element = getContentElementByName("content");
         $ce_name = 'content';
     }
     // CP fields
     $cp = $this->getModel('cpfields');
     $cpfields = $cp->getList(false);
     $assign = $this->getModel('assign');
     $content_id = $assign->_id;
     $item_title = $assign->getTitle();
     $properties = $assign->getProperties();
     $user =& JFactory::getUser();
     $aid = $user->get('aid', 0);
     if ($mainframe->isSite() && $cp_config['frontend_tagging'] != '1') {
         JError::raiseError(500, JText::_('CP_ERR_FUNCTION_DISABLED'));
     }
     if ($aid < $cp_config['editing_level']) {
         JError::raiseError(500, JText::_('CP_ERR_NOAUTH'));
     }
     if (empty($content_id)) {
         JError::raiseError(500, JText::_('CP_ERR_INVALID_ID'));
     }
     $this->assignRef('content_element', $content_element);
     $this->assignRef('ce_name', $ce_name);
     $this->assignRef('cpfields', $cpfields);
     $this->assignRef('content_id', $content_id);
     $this->assignRef('item_title', $item_title);
     $this->assignRef('properties', $properties);
     parent::display($tpl);
 }
    case 0:
        $view = "title";
        break;
    case 1:
        $view = "intro";
        break;
    case 2:
    default:
        $view = "fullintro";
        break;
}
echo "\r\n<table class=\"contentpaneopen" . $params->get('pageclass_sfx') . "\">\r\n\t<tr>\r\n\t\t<td>\n";
// filter by content element type
$content_elements = array();
if ($content_element = JRequest::getVar('content_element', '')) {
    if ($ce = getContentElementByName($content_element)) {
        $content_elements[] = $ce;
    }
}
// I didn't get any valid content element, get all avaible
if (!$content_elements) {
    $content_elements = getInstalledContentElements();
}
foreach ($content_elements as $ce) {
    if (!empty($results[$ce->name])) {
        if ($show_ce_label) {
            echo "<div class=\"cp_ce_label\">" . $ce->label . "</div>";
        }
        foreach ($results[$ce->name] as $ce_name => $row) {
            if ($row->created) {
                $created = JHTML::Date($row->created);
 /**
  * CP Fields assign method
  * @return void
  **/
 function display($tpl = null)
 {
     global $mainframe, $cp_config;
     //require_once(JPATH_COMPONENT_ADMINISTRATOR .DS.'cp_config.php');
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_customproperties' . DS . 'cp_config.php';
     // content element
     $ce_name = JRequest::getVar('ce_name', null, '', 'string');
     if (!($content_element = getContentElementByName("{$ce_name}"))) {
         $content_element = getContentElementByName("content");
         $ce_name = 'content';
     }
     // CP fields
     $cp = $this->getModel('cpvalues');
     $cp->getAllHierarchical();
     $cpvalues = $cp->getCachedRoots();
     $assign = $this->getModel('assignhierarchic');
     $content_id = $assign->_id;
     $item_title = $assign->getTitle();
     $properties = $assign->getProperties();
     $this->_cplist = array();
     // Carga lista de tags asignados
     foreach ($this->getAssignedTags($ce_name, $content_id) as $value) {
         $this->_cplist[] = $value->value_id;
     }
     $this->assignRef('_cplist', $this->_cplist);
     $user =& JFactory::getUser();
     $aid = $user->get('aid', 0);
     if ($mainframe->isSite() && $cp_config['frontend_tagging'] != '1') {
         JError::raiseError(500, JText::_('CP_ERR_FUNCTION_DISABLED'));
     }
     if ($aid < $cp_config['editing_level']) {
         JError::raiseError(500, JText::_('CP_ERR_NOAUTH'));
     }
     if (empty($content_id)) {
         JError::raiseError(500, JText::_('CP_ERR_INVALID_ID'));
     }
     // Construye el objeto PHP que genera el arbol
     foreach ($cpvalues as $root) {
         $this->setTree($root, $cp);
     }
     $query = "SELECT DISTINCT f.*\r\n                    FROM #__custom_properties_fields f\r\n                    JOIN #__custom_properties_values v\r\n                        ON (f.id = v.field_id AND v.parent_id IS NOT NULL)";
     $database = JFactory::getDBO();
     $database->setQuery($query);
     $fields = $database->loadObjectList();
     $j = 0;
     $jsCode = "";
     $divs = "";
     foreach ($fields as $field) {
         //Generamos codigo Javascript que inicializa los arboles
         $i = 0;
         $jsCode .= 'var a' . $j . ' = new Array;';
         foreach ($cpvalues as $row) {
             if ($field->id == $row->field_id) {
                 $this->setJSTree($jsCode, 'a' . $j . '[' . $i . ']', $row);
                 $i++;
             }
         }
         $jsCode .= "t{$j} = new Bs_Tree();";
         $jsCode .= "t{$j}.imageDir = '/zonales/media/system/js/tree/img/win98/';";
         $jsCode .= "t{$j}.checkboxSystemImgDir = '/zonales/media/system/js/checkbox/img/win2k_noBorder/';";
         $jsCode .= "t{$j}.useCheckboxSystem = true;";
         $jsCode .= "t{$j}.checkboxSystemWalkTree = 0;";
         $jsCode .= "t{$j}.useAutoSequence = false;";
         $jsCode .= "t{$j}.checkboxSystemIfPartlyThenFull = false;";
         $jsCode .= "t{$j}.useFolderIcon = false;";
         $jsCode .= "t{$j}.useLeaf = false;";
         $jsCode .= "t{$j}.initByArray(a{$j});";
         $jsCode .= "t{$j}.drawInto('cp_values{$j}');";
         //Generamos codigo HTML que crea los divs donde aparecen los arboles.
         $divs .= "<b>{$field->label}</b>";
         $divs .= '<div id="cp_values' . $j . '" class="cp_values"></div>';
         $j++;
     }
     $this->assignRef('content_element', $content_element);
     $this->assignRef('ce_name', $ce_name);
     $this->assignRef('jsCode', $jsCode);
     $this->assignRef('divs', $divs);
     $this->assignRef('content_id', $content_id);
     $this->assignRef('item_title', $item_title);
     $this->assignRef('properties', $properties);
     parent::display($tpl);
 }
 /** Function that returns data for all content elements.
  * It also fills Search summary, Page nav and search result
  * @param mixed $tag  when set, returns all rows with the relevant tag
  * @return void
  */
 function getData($tag = "")
 {
     $user = JFactory::getUser();
     $aid = $user->get('aid');
     $params = $this->_params;
     $ordering = $this->_ordering;
     $search_pars = array();
     $this->_errors = array();
     // reset errors
     if ($aid < $this->_params->get('result_acl')) {
         $this->setError("result_acl");
     }
     if ($tag != "") {
         // add tag to page title
         if ($tagname = getTagNamebyId($tag, $params)) {
             $this->_tagname = $tagname;
         }
     }
     // filter by content element type
     $content_elements = array();
     if ($content_element = JRequest::getVar('content_element')) {
         if ($ce = getContentElementByName($content_element)) {
             $content_elements[] = $ce;
         }
     }
     // I didn't get any valid content element, get all avaible
     if (!$content_elements) {
         $content_elements = getInstalledContentElements();
     }
     $total = 0;
     $cpq = array();
     foreach ($content_elements as $key => $ce) {
         $cpq[$ce->name] = new CPQuery();
         if ($buffer = $cpq[$ce->name]->getRows($ce, $this->_search_pars, $tag, null, $ordering, 0, $params)) {
             $result[$ce->name] = $buffer;
             $total += count($result[$ce->name]);
         } elseif ($buffer === false) {
             foreach ($cpq[$ce->name]->errors as $error_code) {
                 $this->setError($error_code);
             }
             return;
         } elseif (count($buffer) === 0) {
             /* this ce does not contain any matching record,
              * remove it from content_elements list so that we don't process
              * it nay further
              */
             unset($content_elements[$key]);
         }
     }
     // no point in creating pagination or summary
     // with no result to show
     if ($total === 0) {
         $this->setError("no match");
         return;
     }
     //PAGINATION
     $limit = JRequest::getVar('limit', $params->get('limit'), '', 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     jimport('joomla.html.pagination');
     if ($total <= $limitstart) {
         $limitstart = 0;
     }
     $pageNav = new JPagination($total, $limitstart, $limit);
     $this->_page =& $pageNav;
     /* creates a Result summary that is a list of sections with relevant number of articles found	*/
     if ($params->get('show_result_summary')) {
         $this->_result_summary = $this->_createResultSummary($content_elements, $cpq, $ordering);
     }
     // unset rows out of pagination
     $i = 0;
     foreach ($result as $key => $value) {
         foreach ($result[$key] as $ce => $val) {
             if ($i < $limitstart || $i >= $limitstart + $limit) {
                 unset($result[$key][$ce]);
             }
             $i++;
         }
     }
     $this->_data = $result;
     return $result;
 }
 /** uninstall content element */
 function uninstallContentElement()
 {
     global $option;
     $ce_name = JRequest::getVar('cename', '');
     $return_to = "index2.php?option={$option}&controller=utilities&task=showce";
     if (!($ce = getContentElementByName($ce_name, true))) {
         return $this->setRedirect($return_to, "{$ce} Error, wrong content element name.");
     }
     if (!($xml = $ce->xml)) {
         $this->setRedirect($return_to, "Error, no XML file.");
     }
     if (unlink($ce->xml)) {
         $this->setRedirect($return_to, "Done");
     } else {
         $this->setRedirect($return_to, "Unable to remove {$ce_name}" . ".xml", 'error');
     }
 }