Ejemplo n.º 1
0
 /**
  * Test the JParameter::bind method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testBind()
 {
     $p = new JParameter('');
     // Check binding an array.
     $p->bind(array('foo1' => 'bar1'));
     $this->assertThat($p->get('foo1'), $this->equalTo('bar1'));
     // Check binding an object.
     $object = new stdClass();
     $object->foo1 = 'bar2';
     $p->bind($object);
     $this->assertThat($p->get('foo1'), $this->equalTo('bar2'));
     // Check binding a JSON string.
     $p->bind('{"foo1":"bar4"}');
     $this->assertThat($p->get('foo1'), $this->equalTo('bar4'));
     // Check binding an INI string.
     $p->bind('foo1=bar5');
     $this->assertThat($p->get('foo1'), $this->equalTo('bar5'));
 }
Ejemplo n.º 2
0
 function &getIni()
 {
     static $ini = 0;
     if (empty($ini)) {
         $basepath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jdefender';
         $p = new JParameter('');
         $conf = JD_Vars_Helper::getGroup('configuration');
         $p->bind($conf);
         $ini = $p->toString('ini');
     }
     return $ini;
 }
Ejemplo n.º 3
0
    function saveDefaultAuctionSettings($ob) {

        jimport('joomla.html.parameter');

        $my = JFactory::getUser();
        $config = & JFactory::getConfig();

        $us = JTable::getInstance('bidusersettings');

        $settings = new JParameter(null);

        $paramKeys = array(
            'show_reserve',
            'picture',
            'add_picture',
            'auto_accept_bin',
            'bid_counts',
            'max_price',
            'end_hour',
            'end_minute',
            'auction_type',
            'currency',
            'shipment_info',
            'shipment_price',
            'payment_info',
            'payment_options');

        $vals = array();
        foreach($paramKeys as $k) {
            $v = is_object($ob) ? (isset($ob->$k) ? $ob->$k : null) : (is_array($ob) ? @$ob[$k] : null);
            $vals[$k] = $v;
        }

        //convert end time to GMT
        try {
            $endTime = JFactory::getDate( ' ' . $vals['end_hour'] . ':' . $vals['end_minute'] . ':00', $config->getValue('config.offset'));
            @list($vals['end_hour'],$vals['end_minute']) = explode(':',$endTime->toFormat('%H:%M'));
        } catch(Exception $e) {
            if(JDEBUG) {
                JError::raiseWarning(1,$e->getMessage());
            }
        }


        $settings->bind($vals);

        $us->settings = $settings;
        $us->userid = $my->id;

        return $us->store();
    }
Ejemplo n.º 4
0
 /**
  * Edit a connection
  */
 function edit()
 {
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('visualization', 'Table');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $row->load($cid[0]);
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     // get params definitions
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'visualization.xml');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'visualization.php';
     //build list of visualization plugins
     $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('visualization');
     $lists['plugins'] = $pluginManager->getElementTypeDd($row->plugin, 'plugin', 'class="inputbox"');
     //build list of menus
     $lists['menuselect'] = FabrikHelperMenu::MenuSelect();
     if ($row->id != '') {
         //only existing tables can have a menu linked to them
         $and = "\n AND link LIKE 'index.php?option=com_fabrik&view=visualization%'";
         $and .= " AND params LIKE '%visualizationid=" . $row->id . "%'";
         $menus = FabrikHelperMenu::Links2Menu('component', $and);
     } else {
         $menus = null;
     }
     //get table and connection drop downs
     $db->setQuery("SELECT id AS value, label AS text FROM #__fabrik_tables");
     $rows = $db->loadObjectList();
     $default = '';
     $lists['tables'] = JHTML::_('select.genericlist', $rows, 'table[]', "class=\"inputbox\"  size=\"1\" ", 'value', 'text', $default);
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'visualization.xml');
     $form->bind($row);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('NEVER'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     FabrikViewVisualization::edit($row, $params, $lists, $menus, $pluginManager, $form);
 }
Ejemplo n.º 5
0
 function replace(&$article, &$matches, $count, $regex, $pluginParams)
 {
     for ($i = 0; $i < $count; $i++) {
         // set line params
         $this->setParams($matches[1][$i], array('width' => null, 'height' => null));
         // set default thumbnail size, if no sizes defined
         if (!$this->parameter['width'] && !$this->parameter['height']) {
             $this->parameter['width'] = $pluginParams->get('width', 100);
             $this->parameter['height'] = null;
         }
         // set gallery params
         $params = new JParameter('');
         $params->bind($pluginParams->toArray());
         $params->bind($this->parameter);
         $params->set('cfg_path', 'plugins/content/yoo_gallery/');
         $params->set('cfg_juri', JURI::base());
         $params->set('cfg_jroot', JPATH_ROOT);
         // render gallery
         $gallery =& new YOOGallery($params);
         $replace = $gallery->render();
         // replace
         $article->text = str_replace($matches[0][$i], $replace, $article->text);
     }
 }
Ejemplo n.º 6
0
 function getGeneralForm($workflow)
 {
     $form = new JParameter('');
     $form->addElementPath(JWF_BACKEND_PATH . DS . 'elements');
     $form->loadSetupFile(JPATH_COMPONENT . DS . 'models' . DS . 'workflow.xml');
     $jsOutput = '';
     if ($workflow != null) {
         $form->bind($workflow);
         $jsOutput = JHTML::_('jwf.startJSBlock', 2);
         $jsOutput .= JHTML::_('jwf.indentedLine', 'adminGroupId =' . $workflow->admin_gid . ';', 2);
         $jsOutput .= JHTML::_('jwf.indentedLine', 'window.addEvent("load",function(){', 3);
         $jsOutput .= JHTML::_('jwf.indentedLine', 'var s;', 4);
         $jsOutput .= JHTML::_('jwf.indentedLine', 'var tempHook;', 4);
         foreach ($workflow->stations as $s) {
             $s->activeHooks = unserialize(base64_decode($s->activeHooks));
             $jsOutput .= JHTML::_('jwf.indentedLine', "s = new Object();", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.id    = {$s->id};", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.title = '{$s->title}';", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.task  = '{$s->task}';", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.allocatedTime = {$s->allocatedTime};", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.acl   =  {id:{$s->group},name:aclLists['" . $workflow->acl . "'][{$s->group}]};", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.fields= '{$s->fields}';", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.activeValidations= '{$s->activeValidations}';", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "s.activeHooks = new Array();", 4);
             $jsOutput .= JHTML::_('jwf.indentedLine', "tempHook = new Object();", 4);
             foreach ($s->activeHooks as $hookName => $hookData) {
                 $parameters = JArrayHelper::fromObject($hookData);
                 foreach ($parameters as $key => $value) {
                     $value = addslashes($value);
                     $value = str_replace("\r\n", "\n", $value);
                     $value = str_replace("\n", '\\n', $value);
                     $jsOutput .= JHTML::_('jwf.indentedLine', "tempHook.{$key} = '{$value}';", 4);
                 }
                 $jsOutput .= JHTML::_('jwf.indentedLine', "s.activeHooks['{$hookName}'] = tempHook;", 4);
             }
             $jsOutput .= JHTML::_('jwf.indentedLine', "addElement(s);", 4);
         }
         $jsOutput .= JHTML::_('jwf.indentedLine', '});', 3);
         $jsOutput .= JHTML::_('jwf.endJSBlock', 2);
     }
     return $jsOutput . $form->render('params');
 }
Ejemplo n.º 7
0
 function createMenuJ15($menu, $submenu)
 {
     jimport('joomla.utilities.string');
     jimport('joomla.application.component.helper');
     $config = KunenaFactory::getConfig();
     $component_id = JComponentHelper::getComponent('com_kunena')->id;
     // First fix all broken menu items
     $query = "UPDATE #__menu SET componentid={$this->db->quote($component_id)} WHERE type = 'component' AND link LIKE '%option=com_kunena%'";
     $this->db->setQuery($query);
     $this->db->query();
     if ($this->db->getErrorNum()) {
         throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
     }
     // Find out if menu exists
     $query = "SELECT id FROM `#__menu_types` WHERE `menutype`='kunenamenu';";
     $this->db->setQuery($query);
     $moduleid = (int) $this->db->loadResult();
     if ($this->db->getErrorNum()) {
         throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
     }
     // Do not touch existing menu
     if ($moduleid) {
         return;
     }
     // Create new Joomla menu for Kunena
     if (!$moduleid) {
         // Create a menu type for the Kunena menu
         $query = "REPLACE INTO `#__menu_types` (`id`, `menutype`, `title`, `description`) VALUES\n\t\t\t\t\t\t\t({$moduleid}, 'kunenamenu', {$this->db->Quote(JText::_('COM_KUNENA_MENU_TITLE'))} , {$this->db->Quote(JText::_('COM_KUNENA_MENU_TITLE_DESC'))} )";
         $this->db->setQuery($query);
         $this->db->query();
         if ($this->db->getErrorNum()) {
             throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
         }
     }
     // Forum
     $query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menu['link'])} AND `menutype`='kunenamenu';";
     $this->db->setQuery($query);
     $parentid = (int) $this->db->loadResult();
     if ($this->db->getErrorNum()) {
         throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
     }
     if (!$parentid) {
         $params = new JParameter('');
         $params->bind($menu['params']);
         $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES\n\t\t\t\t\t\t\t({$parentid}, 'kunenamenu', {$this->db->quote($menu['name'])}, {$this->db->quote($menu['alias'])}, {$this->db->quote($menu['link'])}, 'component', 1, 0, {$component_id}, 0, 1, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);";
         $this->db->setQuery($query);
         $this->db->query();
         if ($this->db->getErrorNum()) {
             throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
         }
         $parentid = (int) $this->_db->insertId();
     }
     // Submenu (shown in Kunena)
     $defaultmenu = 0;
     $ordering = 0;
     foreach ($submenu as $menuitem) {
         $ordering++;
         //			$query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menuitem['link'])} AND `menutype`='kunenamenu';";
         //			$this->db->setQuery ( $query );
         //			$id = ( int ) $this->db->loadResult ();
         //			if ($this->db->getErrorNum ())
         //				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
         $id = 0;
         if (!$id) {
             $params = new JParameter('');
             $params->bind($menuitem['params']);
             $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES\n\t\t\t\t\t\t\t\t({$id}, 'kunenamenu', {$this->db->quote($menuitem['name'])}, {$this->db->quote($menuitem['alias'])}, {$this->db->quote($menuitem['link'])},'component', 1, {$parentid}, {$component_id}, 1, {$ordering}, 0, '0000-00-00 00:00:00', 0, 0, {$menuitem['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);";
             $this->db->setQuery($query);
             $this->db->query();
             if ($this->db->getErrorNum()) {
                 throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
             }
             $id = (int) $this->_db->insertId();
             if (!$defaultmenu || isset($menuitem['default']) && $config->defaultpage == $menuitem['default']) {
                 $defaultmenu = $id;
             }
         }
     }
     if ($defaultmenu) {
         $query = "UPDATE `#__menu` SET `link`={$this->db->quote($menu['link'] . "&defaultmenu={$defaultmenu}")} WHERE id={$parentid}";
         $this->db->setQuery($query);
         $this->db->query();
         if ($this->db->getErrorNum()) {
             throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
         }
     }
     // Finally add forum menu link to default menu
     $jmenu = JMenu::getInstance('site');
     $dmenu = $jmenu->getDefault();
     $query = "SELECT id, name, type, link, published FROM `#__menu` WHERE `alias` IN ('forum', 'kunenaforum', {$this->db->quote(JText::_('COM_KUNENA_MENU_FORUM_ALIAS'))}) AND `menutype`={$this->db->quote($dmenu->menutype)}";
     $this->db->setQuery($query, 0, 1);
     $menualias = $this->db->loadObject();
     if ($this->db->getErrorNum()) {
         throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
     }
     // We do not want to replace users own menu items (just alias or deprecated link to Kunena)
     if (!$menualias || $menualias->type == 'menulink' || $menualias->link == 'index.php?option=com_kunena') {
         $id = $menualias ? intval($menualias->id) : 0;
         // Keep state (default=unpublished) and name (default=Forum)
         $published = $menualias ? intval($menualias->published) : 0;
         $name = $menualias ? $menualias->name : $menu['name'];
         $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES\n\t\t\t\t\t\t({$id}, {$this->db->quote($dmenu->menutype)}, {$this->db->quote($name)}, 'kunenaforum', 'index.php?Itemid={$parentid}', 'menulink', {$published}, 0, 0, 0, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, 'menu_item={$parentid}{$menu['params']}\r\n\r\n', 0, 0, 0);";
         $this->db->setQuery($query);
         $this->db->query();
         if ($this->db->getErrorNum()) {
             throw new KunenaInstallerException($this->db->getErrorMsg(), $this->db->getErrorNum());
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Edit a table
  */
 function edit()
 {
     $app =& JFactory::getApplication();
     $session =& JFactory::getSession();
     $session->clear('com_fabrik.admin.table.edit.model');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'table.php';
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('table', 'Table');
     $acl =& JFactory::getACL();
     $config =& JFactory::getConfig();
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $connectionTables = array();
     //  this only appears if you are automatically creating the table from an existing form - which has no table associated with it
     $fabrikid = JRequest::getVar('fabrikid', '', 'get');
     $row->load($cid[0]);
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'model' . DS . 'table.xml');
     $lists['tablejoin'] = "";
     //$lists['defaultJoinTables'] = '[]';
     $lists['defaultJoinTables'] = array();
     $lists['linkedtables'] = array();
     $connModel =& JModel::getInstance('Connection', 'FabrikModel');
     $model =& JModel::getInstance('Table', 'FabrikModel');
     $model->setId($cid[0]);
     $model->_table =& $row;
     $formModel =& $model->getForm();
     $aJoinObjs = array();
     if ($this->_task != 'edit') {
         $row->template = 'default';
         $realCnns = $connModel->getConnections();
         $defaultCid = '';
         foreach ($realCnns as $realCnn) {
             if ($realCnn->default == 1) {
                 $defaultCid = $realCnn->id;
             }
         }
         $javascript = "onchange=\"changeDynaList('db_table_name', connectiontables, document.adminForm.connection_id.options[document.adminForm.connection_id.selectedIndex].value, 0, 0);\"";
         $lists['connections'] = $connModel->getConnectionsDd($realCnns, $javascript, 'connection_id', $defaultCid);
         $connectionTables = $connModel->getConnectionTables($realCnns);
         $javascript = '';
         $lists['tablename'] = '<select name="db_table_name" id="tablename" class="inputbox" size="1" >';
         if ($defaultCid == '') {
             $lists['tablename'] .= '<option value="" selected="selected">' . JText::_('CHOOSE A CONNECTION FIRST') . '</option>';
         } else {
             foreach ($connectionTables[$defaultCid] as $t) {
                 $lists['tablename'] .= '<option value="' . $t->value . '">' . $t->text . '</option>';
             }
         }
         $lists['tablename'] .= '</select>';
         $lists['order_by'][] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['group_by'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['filter-fields'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['db_primary_key'] = JText::_('AVAILABLE AFTER TABLE SAVED');
     } else {
         //if record already exists then you can't change the form or table it points to
         // fail if checked out not by 'me'
         if ($row->checked_out && $row->checked_out != $user->get('id')) {
             $app->redirect('index.php?option=com_fabrik', 'The connection ' . $row->description . ' is currently being edited by another administrator');
         }
         $row->checkout($user->get('id'));
         if ($row->connection_id != "-1") {
             $sql = "SELECT description FROM #__fabrik_connections WHERE id = " . (int) $row->connection_id;
             $db->setQuery($sql);
             $lists['connections'] = $db->loadResult();
             $lists['tablename'] = "<input type='hidden' name='db_table_name' value='{$row->db_table_name}' />{$row->db_table_name}";
         } else {
             $lists['connections'] = "no database";
             $lists['tablename'] = "no table";
         }
         $lists['connections'] .= "<input type=\"hidden\" value=\"{$row->connection_id}\" id=\"connection_id\" name=\"connection_id\" />";
         $formModel->setId($row->form_id);
         $formTable =& $formModel->getForm();
         $formModel->getGroupsHiarachy();
         //table join info
         $sql = "SELECT * FROM #__fabrik_joins WHERE table_id = " . (int) $row->id . " AND element_id = 0";
         $db->setQuery($sql);
         $aJoinObjs = $db->loadObjectList();
         $lists['joins'] =& $aJoinObjs;
         $lists['order_by'] = array();
         $orderbys = explode(GROUPSPLITTER2, $row->order_by);
         foreach ($orderbys as $orderby) {
             $lists['order_by'][] = $formModel->getElementList('order_by[]', $orderby, true, false, true);
         }
         $lists['group_by'] = $formModel->getElementList('group_by', $row->group_by, true, false, true);
         //needs to be table.element format for where statement to work
         $formModel->_addDbQuote = true;
         $lists['filter-fields'] = $formModel->getElementList('params[filter-fields][]', '', false, false, true);
         $lists['db_primary_key'] = $formModel->getElementList('db_primary_key', $row->db_primary_key);
         $formModel->_addDbQuote = false;
         //but you can now add table joins
         $connModel->setId($row->connection_id);
         $connModel->getConnection($row->connection_id);
         ///load in current connection
         $joinFromTables[] = JHTML::_('select.option', '', '-');
         $joinFromTables[] = JHTML::_('select.option', $row->db_table_name, $row->db_table_name);
         $lists['defaultjoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_key');
         $lists['tablejoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_join_key');
         //make a drop down validation type for each validation
         $aActiveJoinTypes = array();
         if (is_array($aJoinObjs)) {
             for ($ff = 0; $ff < count($aJoinObjs); $ff++) {
                 $oJoin = $aJoinObjs[$ff];
                 $fields = array();
                 $aFields = $model->getDBFields($oJoin->join_from_table);
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinFormFields = $fields;
                 $aFields = $model->getDBFields($oJoin->table_join);
                 $fields = array();
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinToFields = $fields;
             }
             $lists['defaultJoinTables'] = $connModel->getThisTables(true);
         }
     }
     if ($row->id != '') {
         //only existing tables can have a menu linked to them
         $and = "\n AND link LIKE '%index.php?option=com_fabrik%' AND link LIKE '%view=table%'";
         $and .= " AND params LIKE '%tableid=" . $row->id . "'";
         $menus = FabrikHelperMenu::Links2Menu('component', $and);
     } else {
         $menus = null;
     }
     $lists['filter-access'] = $this->getFilterACLList($row);
     $lists['menuselect'] = FabrikHelperMenu::MenuSelect();
     $lists['tableTemplates'] = FabrikHelperAdminHTML::templateList('table', 'template', $row->template);
     // make the filter action drop down
     $filterActions[] = JHTML::_('select.option', 'onchange', JText::_('ON CHANGE'));
     $filterActions[] = JHTML::_('select.option', 'submitform', JText::_('SUBMIT FORM'));
     $lists['filter_action'] = JHTML::_('select.genericlist', $filterActions, 'filter_action', 'class="inputbox" size="1" ', 'value', 'text', $row->filter_action);
     //make the order direction drop down
     $orderDir[] = JHTML::_('select.option', 'ASC', JText::_('ASCENDING'));
     $orderDir[] = JHTML::_('select.option', 'DESC', JText::_('DESCENDING'));
     $orderdirs = explode(GROUPSPLITTER2, $row->order_dir);
     $lists['order_dir'] = array();
     foreach ($orderdirs as $orderdir) {
         $lists['order_dir'][] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', 'class="inputbox" size="1" ', 'value', 'text', $orderdir);
     }
     $linkedTables = $model->getJoinsToThisKey();
     $aExisitngLinkedTables = $params->get('linkedtable', '', '_default', 'array');
     $aExisitngLinkedForms = $params->get('linkedform', '', '_default', 'array');
     $aExistingTableHeaders = $params->get('linkedtableheader', '', '_default', 'array');
     $aExistingFormHeaders = $params->get('linkedformheader', '', '_default', 'array');
     $linkedform_linktype = $params->get('linkedform_linktype', '', '_default', 'array');
     $linkedtable_linktype = $params->get('linkedtable_linktype', '', '_default', 'array');
     $tableLinkTexts = $params->get('linkedtabletext', '', '_default', 'array');
     $formLinkTexts = $params->get('linkedformtext', '', '_default', 'array');
     $lists['linkedtables'] = array();
     $f = 0;
     $used = array();
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedTables)) {
             $aExisitngLinkedTables[$f] = '0';
         }
         if (!array_key_exists($f, $linkedtable_linktype)) {
             $linkedtable_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedTables);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedTables)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedTables) || JArrayHelper::getValue($aExisitngLinkedTables, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el = '<label><input name="params[linkedtable][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el .= '<label><input name="params[linkedtable][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedtable_linktype) || JArrayHelper::getValue($linkedtable_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType1 = '<label><input name="params[linkedtable_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType1 .= '<label><input name="params[linkedtable_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $tableHeader = '<input name="params[linkedtableheader][' . $key . ']" value="' . @$aExistingTableHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $hover = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_table_heading}";
         $tableLinkText = '<input name="params[linkedtabletext][' . $key . ']" value="' . @$tableLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $hover, $el, $tableHeader, $linkType1, $tableLinkText);
         $lists['linkedtables'][$index] = $linkedArray;
     }
     ksort($lists['linkedtables']);
     $lists['linkedforms'] = array();
     $f = 0;
     $used = array();
     /***/
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedForms)) {
             $aExisitngLinkedForms[$f] = '0';
         }
         if (!array_key_exists($f, $linkedform_linktype)) {
             $linkedform_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedForms);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedForms)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedForms) || JArrayHelper::getValue($aExisitngLinkedForms, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el2 = '<label><input name="params[linkedform][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el2 .= '<label><input name="params[linkedform][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedform_linktype) || JArrayHelper::getValue($linkedform_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType2 = '<label><input name="params[linkedform_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType2 .= '<label><input name="params[linkedform_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $formHeader = '<input name="params[linkedformheader][' . $key . ']" value="' . @$aExistingFormHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $formLinkText = '<input name="params[linkedformtext][' . $key . ']" value="' . @$formLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $el2, $formHeader, $linkType2, $formLinkText);
         $linkedArray['formhover'] = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_form_heading}";
         $lists['linkedforms'][$index] = $linkedArray;
     }
     ksort($lists['linkedforms']);
     /*****/
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('table');
     // Create the form (publish dates should be stored as UTC)
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'table.xml');
     $form->bind($row);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('NEVER'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     $form->loadINI($row->attribs);
     $session->set('com_fabrik.admin.table.edit.model', $model);
     FabrikViewTable::edit($row, $lists, $connectionTables, $menus, $fabrikid, $params, $pluginManager, $model, $form);
 }
Ejemplo n.º 9
0
 /**
  *
  */
 public function ajaxSaveSettings($postvars)
 {
     // Check permissions
     $my =& JFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     $objResponse = new JAXResponse();
     $appsModel = CFactory::getModel('apps');
     $appName = $postvars['appname'];
     $id = $postvars['appid'];
     // @rule: Test if app is core app as we need to add into the db
     $pluginId = $appsModel->getPluginId($appName);
     $appParam = new JParameter($appsModel->getPluginParams($pluginId));
     if ($pluginId && $my->id != 0 && $appParam->get('coreapp')) {
         // Add new app in the community plugins table
         $appsModel->addApp($my->id, $appName);
         // @rule: For core applications, the ID might be referring to Joomla's id. Get the correct id if needed.
         $id = $appsModel->getUserApplicationId($appName, $my->id);
     }
     // Make sure this is valid for current user
     if (!$appsModel->isOwned($my->id, $id)) {
         // It could be that the app is a core app.
         $objResponse->addAlert('CC PERMISSION ERROR');
         return $objResponse->sendResponse();
     }
     $post = array();
     // convert $postvars to normal post
     $pattern = "'params\\[(.*?)\\]'s";
     for ($i = 0; $i < count($postvars); $i++) {
         if (!empty($postvars[$i]) && is_array($postvars[$i])) {
             $key = $postvars[$i][0];
             // Blogger view
             preg_match($pattern, $key, $matches);
             if ($matches) {
                 $key = $matches[1];
             }
             $post[$key] = $postvars[$i][1];
         }
     }
     $xmlPath = JPATH_COMPONENT . DS . 'applications' . DS . $appName . DS . $appName . '.xml';
     $params = new JParameter($appsModel->getUserAppParams($id), $xmlPath);
     $params->bind($post);
     //echo $params->toString();
     $appsModel->storeParams($id, $params->toString());
     $objResponse->addScriptCall('cWindowHide');
     return $objResponse->sendResponse();
 }
Ejemplo n.º 10
0
 /**
  * AJAX method to save a field
  * 
  * @param	int	id	Current field id
  * @param	Array data	The fields data
  * 
  * @return	JAXResponse object	Azrul's AJAX Response object
  **/
 function ajaxSaveField($id, $data)
 {
     $user =& JFactory::getUser();
     if ($user->get('guest')) {
         JError::raiseError(403, JText::_('CC ACCESS FORBIDDEN'));
         return;
     }
     $response = new JAXResponse();
     // Load the JTable Object.
     $row =& JTable::getInstance('profiles', 'CommunityTable');
     $row->load($id);
     $isValid = true;
     $row->bindAjaxPost($data);
     // override the option visiable, registration and required for label type.
     if ($row->type == 'label') {
         $row->visible = 0;
         $row->required = 0;
     }
     // Do some validation before blindly saving the profile.
     if (empty($row->name)) {
         $error = JText::_('CC NAME SHOULD NOT BE LEFT EMPTY');
         $response->addScriptCall('joms.jQuery("#error-notice").html("' . $error . '");');
         $isValid = false;
     }
     if (empty($row->fieldcode)) {
         $error = JText::_('CC FIELD CODE SHOULD NOT BE LEFT EMPTY');
         $response->addScriptCall('joms.jQuery("#error-notice").html("' . $error . '");');
         $isValid = false;
     }
     if ($row->required && !$row->registration) {
         $error = JText::_('CC A FIELD IN REQUIRED SHOULD SET AS REGISTRATION AS WELL');
         $response->addScriptCall('joms.jQuery("#error-notice").html("' . $error . '");');
         $isValid = false;
     }
     if ($isValid) {
         $groupOrdering = isset($data['group']) ? $data['group'] : '';
         /* Now, save optional params items */
         $xmlPath = JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'fields' . DS . $row->type . '.xml';
         if (JFile::exists($xmlPath)) {
             $postvars = $data;
             $post = array();
             // convert $postvars to normal post
             $pattern = "'params\\[(.*?)\\]'s";
             for ($i = 0; $i < count($postvars); $i++) {
                 if (!empty($postvars[$i]) && is_array($postvars[$i])) {
                     $key = $postvars[$i][0];
                     // @TODO: support 'usergroup' param type
                     preg_match($pattern, $key, $matches);
                     if ($matches) {
                         $key = $matches[1];
                         $post[$key] = $postvars[$i][1];
                     }
                 }
             }
             $params = new JParameter('', $xmlPath);
             $params->bind($post);
             $row->params = $params->toString();
         }
         $row->store($groupOrdering);
         $parent = '';
         // Get the view
         $view =& $this->getView('profiles', 'html');
         if ($id != 0) {
             $name = '<a href="javascript:void(0);" onclick="azcommunity.editField(\'' . $row->id . '\');">' . $row->name . '</a>';
             $type = '<span id="type' . $row->id . '" onclick="$(\'typeOption\').style.display = \'block\';$(this).style.display = \'none\';">' . JString::ucfirst($row->type) . '</span>';
             $publish = $view->getPublish($row, 'published', 'profiles,ajaxTogglePublish');
             if ($row->type == 'label') {
                 $required = $view->showPublish($row, 'required');
                 $visible = $view->showPublish($row, 'visible');
             } else {
                 $required = $view->getPublish($row, 'required', 'profiles,ajaxTogglePublish');
                 $visible = $view->getPublish($row, 'visible', 'profiles,ajaxTogglePublish');
             }
             $registration = $view->getPublish($row, 'registration', 'profiles,ajaxTogglePublish');
             // Set the parent id
             $parent = $row->id;
             // Update the rows in the table at the page.
             //@todo: need to update the title in a way looks like Joomla initialize the tooltip on document ready
             $response->addAssign('name' . $row->id, 'innerHTML', $name);
             $response->addAssign('type' . $row->id, 'innerHTML', $type);
             $response->addAssign('published' . $row->id, 'innerHTML', $publish);
             $response->addAssign('required' . $row->id, 'innerHTML', $required);
             $response->addAssign('visible' . $row->id, 'innerHTML', $visible);
             $response->addAssign('registration' . $row->id, 'innerHTML', $registration);
             $response->addAssign('min' . $row->id, 'value', $row->min);
             $response->addAssign('max' . $row->id, 'value', $row->max);
         } else {
             $response->addScriptCall('window.location.href = "' . JURI::base() . 'index.php?option=com_community&view=profiles";');
         }
         $response->addScriptCall('cWindowHide();');
     } else {
         //release the form input back to enabled.
         $response->addScriptCall('joms.jQuery(\'#cWindowContent\').find(\'input, textarea, button\').attr(\'disabled\', false)');
     }
     $response->sendResponse();
 }
Ejemplo n.º 11
0
 /**
  * Convert the PlugIn parameters to an object
  * and initialise and add any missing parameters
  *
  */
 function loadParams($row, $params_array)
 {
     $txt = array();
     foreach ($params_array as $k => $v) {
         $txt[] = "{$k}={$v}";
     }
     $ini_string = implode("\n", $txt);
     $params = new JParameter($ini_string);
     //echo '<div>$params->get("days"): '.print_r($params->get("days"), true).'</div>';
     $params->bind($row->params);
     //echo '<div>$params->get("days"): '.print_r($params->get("days"), true).'</div>';
     return $params;
 }
Ejemplo n.º 12
0
 public function save()
 {
     jimport('joomla.user.helper');
     // Load the old row if editing an existing user.
     if (!$this->_new) {
         $old_row = $this->getService('com://admin/users.database.table.users')->select($this->id, KDatabase::FETCH_ROW);
     }
     $user = JFactory::getUser();
     // Validate received data.
     if (($this->_new || isset($this->_modified['name'])) && trim($this->name) == '') {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_('Please enter a name!'));
         return false;
     }
     if (($this->_new || isset($this->_modified['username'])) && trim($this->username) == '') {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_('Please enter a username!'));
         return false;
     }
     if (($this->_new || isset($this->_modified['username'])) && preg_match('#[<>"\'%;()&]#i', $this->username) || strlen(utf8_decode($this->username)) < 2) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_('Please enter a valid username. No spaces, at least 2 characters ' . 'and must contain <strong>only</strong> letters and numbers.'));
         return false;
     }
     if (isset($this->_modified['username'])) {
         $query = $this->getTable()->getDatabase()->getQuery()->where('username', '=', $this->username)->where('id', '<>', (int) $this->id);
         $total = $this->getService('com://admin/users.database.table.users')->count($query);
         if ($total) {
             $this->setStatus(KDatabase::STATUS_FAILED);
             $this->setStatusMessage(JText::_('This username is already in use.'));
             return false;
         }
     }
     if (($this->_new || isset($this->_modified['email'])) && trim($this->email) == '' || !$this->getService('koowa:filter.email')->validate($this->email)) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_('Please enter a valid e-mail address.'));
         return false;
     }
     if (isset($this->_modified['email'])) {
         $query = $this->getTable()->getDatabase()->getQuery()->where('email', '=', $this->email)->where('id', '<>', (int) $this->id);
         $total = $this->getService('com://admin/users.database.table.users')->count($query);
         if ($total) {
             $this->setStatus(KDatabase::STATUS_FAILED);
             $this->setStatusMessage(JText::_('This e-mail address is already registered.'));
             return false;
         }
     }
     /*
      * If username field is an email it has to be the same with email field.
      * This removes the possibilitiy that a user can get locked out of her account
      * if someone else uses that username as the email field.
      */
     if (KService::get('koowa:filter.email')->validate($this->username) === true && $this->username !== $this->email) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_('Your e-mail and username should match if you want to use an e-mail address as your username.'));
         return false;
     }
     // Don't allow users to block themselves.
     if (isset($this->_modified['enabled']) && !$this->_new && $user->id == $this->id && !$this->enabled) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("You can't block yourself!"));
         return false;
     }
     // Don't allow to save a user without a group.
     if (($this->_new || isset($this->_modified['users_group_id'])) && !$this->users_group_id) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("You can't create a user without a user group."));
         return false;
     }
     // Don't allow users below super administrator to edit a super administrator.
     if (!$this->_new && isset($this->_modified['users_group_id']) && $old_row->users_group_id == 25 && $user->gid != 25) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("You can't edit a super administrator account."));
         return false;
     }
     // Don't allow users below super administrator to create an administrators.
     if (isset($this->_modified['users_group_id']) && $this->users_group_id == 24 && !($user->gid == 25 || $user->id == $this->id && $user->gid == 24)) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("You can't create a user with this user group level. " . "Only super administrators have this ability."));
         return false;
     }
     // Don't allow users below super administrator to create a super administrator.
     if (isset($this->_modified['users_group_id']) && $this->users_group_id == 25 && $user->gid != 25) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("You can't create a user with this user group level. " . "Only super administrators have this ability."));
         return false;
     }
     // Don't allow users to change the user level of the last active super administrator.
     if (isset($this->_modifid['users_group_id']) && $old_row->users_group_id != 25) {
         $query = $this->getTable()->getDatabase()->getQuery()->where('users_group_id', '=', 25)->where('enabled', '=', 1);
         $total = $this->getService('com://admin/users.database.table.users')->count($query);
         if ($total <= 1) {
             $this->setStatus(KDatabase::STATUS_FAILED);
             $this->setStatusMessage(JText::_("You can't change this user's group because " . "the user is the only active super administrator for your site."));
             return false;
         }
     }
     // Check if passwords match.
     if (isset($this->_modified['password']) && $this->password != $this->password_verify) {
         $this->setStatus(KDatabase::STATUS_FAILED);
         $this->setStatusMessage(JText::_("Passwords don't match!"));
         return false;
     }
     // Generate a random password if empty and the record is new.
     if ($this->_new && !$this->password) {
         $this->password = $this->getService('com://admin/users.helper.password')->getRandom();
         $this->password_verify = $this->password;
     }
     if (isset($this->_modified['password']) && $this->password) {
         // Encrypt password.
         $salt = $this->getService('com://admin/users.helper.password')->getRandom(32);
         $password = $this->getService('com://admin/users.helper.password')->getCrypted($this->password, $salt);
         $this->password = $password . ':' . $salt;
     } else {
         $this->password = $old_row->password;
         unset($this->_modified['password']);
     }
     if ($this->_new) {
         $this->registered_on = gmdate('Y-m-d H:i:s', time());
     }
     $query = $this->getTable()->getDatabase()->getQuery()->select('name')->where('id', '=', $this->users_group_id);
     $this->group_name = $this->getService('com://admin/users.database.table.groups')->select($query, KDatabase::FETCH_FIELD);
     // Set parameters.
     if (isset($this->_modified['params'])) {
         $params = new JParameter('');
         $params->bind($this->_data['params']);
         $this->params = $params->toString();
         if (!$this->_new && $this->_data['params'] == $old_row->params->toString()) {
             unset($this->_modified['params']);
         }
     }
     // Need to reverse the value of 'enabled', because the mapped column is 'block'.
     if ($this->_new || isset($this->_modified['enabled'])) {
         $this->enabled = $this->enabled ? 0 : 1;
     }
     if (!parent::save()) {
         return false;
     }
     // Syncronize ACL.
     if ($this->_status == KDatabase::STATUS_CREATED) {
         $aro = $this->getService('com://admin/groups.database.row.aro')->setData(array('section_value' => 'users', 'value' => $this->id, 'name' => $this->name));
         $aro->save();
         $this->getService('com://admin/groups.database.row.arosgroup')->setData(array('group_id' => $this->users_group_id, 'aro_id' => $aro->id))->save();
     } else {
         if (isset($this->_modified['name']) || isset($this->_modified['users_group_id'])) {
             $aro = $this->getService('com://admin/groups.database.table.aros')->select(array('value' => $this->id), KDatabase::FETCH_ROW);
             if (isset($this->_modified['name'])) {
                 $aro->name = $this->name;
                 $aro->save();
             }
             if (isset($this->_modified['users_group_id'])) {
                 $this->getService('com://admin/groups.database.table.arosgroups')->select(array('aro_id' => $aro->id), KDatabase::FETCH_ROW)->delete();
                 $this->getService('com://admin/groups.database.table.arosgroups')->select(null, KDatabase::FETCH_ROW)->setData(array('group_id' => $this->users_group_id, 'aro_id' => $aro->id))->save();
             }
         }
     }
     return true;
 }
Ejemplo n.º 13
0
 public function save()
 {
     // Validate name
     if ($this->isModified('name') && trim($this->name) == '') {
         $this->setStatus(Library\Database::STATUS_FAILED);
         $this->setStatusMessage(\JText::_('Please enter a name'));
         return false;
     }
     if ($this->isModified('email')) {
         // Validate E-mail
         if (!$this->getObject('lib:filter.email')->validate($this->email)) {
             $this->setStatus(Library\Database::STATUS_FAILED);
             $this->setStatusMessage(\JText::_('Please enter a valid E-mail address'));
             return false;
         }
         // Check if E-mail address is not already being used
         $query = $this->getObject('lib:database.query.select')->where('email = :email')->bind(array('email' => $this->email));
         if ($this->getObject('com:users.database.table.users')->count($query)) {
             $this->setStatus(Library\Database::STATUS_FAILED);
             $this->setStatusMessage(\JText::_('The provided E-mail address is already registered'));
             return false;
         }
     }
     // Check if the attached role exists
     if ($this->isModified('role_id') && $this->getRole()->isNew()) {
         $this->setStatus(Library\Database::STATUS_FAILED);
         $this->setStatusMessage('Invalid role');
         return false;
     }
     // Set parameters.
     if ($this->isModified('params')) {
         $params = new \JParameter('');
         $params->bind($this->_data['params']);
         $this->params = $params->toString();
         /*if(!$this->isNew() && $this->_data['params'] == $current->params->toString()) {
               unset($this->_modified['params']);
           }*/
     }
     if ($this->isModified('role_id')) {
         // Clear role cache
         $this->_role = null;
     }
     if (!$this->isNew()) {
         // Load the current user row for checks.
         $current = $this->getObject('com:users.database.table.users')->select($this->id, Library\Database::FETCH_ROW);
         // There must be at least one enabled super administrator
         if (($this->isModified('role_id') || $this->isModified('enabled') && !$this->enabled) && $current->role_id == 25) {
             $query = $this->getObject('lib:database.query.select')->where('enabled = :enabled')->where('users_role_id = :role_id')->bind(array('enabled' => 1, 'role_id' => 25));
             if ($this->getObject('com:users.database.table.users')->count($query) <= 1) {
                 $this->setStatus(Library\Database::STATUS_FAILED);
                 $this->setStatusMessage('There must be at least one enabled super administrator');
                 return false;
             }
         }
     }
     return parent::save();
 }
Ejemplo n.º 14
0
	public function display($viewName, $layout='default', $template=null, $params = array()) {
		$viewName = preg_replace( '/[^A-Z0-9_]/i', '', $viewName );
		$view = "KunenaView{$viewName}";
		$model = "KunenaModel{$viewName}";

		// load Kunena main language file so we can leverage language strings from it
		KunenaFactory::loadLanguage();

		require_once KPATH_SITE . '/views/common/view.html.php';
		require_once KPATH_SITE . '/models/common.php';

		if ( !class_exists( $view ) ) {
			$vpath = KPATH_SITE . '/views/'.$viewName.'/view.html.php';
			if (!is_file($vpath)) return;
			require_once $vpath;
		}
		if ( $viewName != 'common' && !class_exists( $model ) ) {
			$mpath = KPATH_SITE . '/models/'.$viewName.'.php';
			if (!is_file($mpath)) return;
			require_once $mpath;
		}

		$view = new $view ( array ('base_path' => KPATH_SITE ) );
		if (!($params instanceof JParameter)) {
			$parameters = new JParameter('');
			$parameters->bind($params);
		} else {
			$parameters = $params;
		}
		$parameters->set('layout', $layout);
		// Push the model into the view (as default).
		$model = new $model ();
		$model->initialize($parameters);
		$view->setModel ( $model, true );

		// Add template path
		$ktemplate = KunenaFactory::getTemplate();
		$templatepath = KPATH_SITE."/{$ktemplate->getPath()}/html/";
		$view->addTemplatePath($templatepath.$viewName);
		if ($parameters->get('templatepath')) $view->addTemplatePath($parameters->get('templatepath'));

		if ($viewName != 'common') {
			$view->common = new KunenaViewCommon ( array ('base_path' => KPATH_SITE ) );
			$view->common->addTemplatePath($templatepath.'common');
		}
		// Push document object into the view.
		$view->assignRef ( 'document', JFactory::getDocument() );

		// Render the view.
		$view->displayLayout ($layout, $template);
	}
Ejemplo n.º 15
0
	function createMenuJ15($menu, $submenu) {
		jimport( 'joomla.utilities.string' );
		jimport( 'joomla.application.component.helper' );
		kimport('kunena.factory');

		$config = KunenaFactory::getConfig();

		$component_id = JComponentHelper::getComponent('com_kunena')->id;

		// First fix all broken menu items
		$query = "UPDATE #__menu SET componentid={$this->db->quote($component_id)} WHERE type = 'component' AND link LIKE '%option=com_kunena%'";
		$this->db->setQuery ( $query );
		$this->db->query ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

		// Find out if menu exists
		$query = "SELECT id FROM `#__menu_types` WHERE `menutype`='kunenamenu';";
		$this->db->setQuery ( $query );
		$moduleid = ( int ) $this->db->loadResult ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

		// Do not touch existing menu
		if ($moduleid) {
			return;
		}

		// Create new Joomla menu for Kunena
		if (! $moduleid) {
			// Create a menu type for the Kunena menu
			$query = "REPLACE INTO `#__menu_types` (`id`, `menutype`, `title`, `description`) VALUES
							($moduleid, 'kunenamenu', {$this->db->Quote( JText::_ ( 'COM_KUNENA_MENU_TITLE' ))} , {$this->db->Quote(JText::_ ( 'COM_KUNENA_MENU_TITLE_DESC' ))} )";
			$this->db->setQuery ( $query );
			$this->db->query ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

			// Now get the menu id again, we need it, in order to publish the menu module
			$query = "SELECT id FROM `#__menu_types` WHERE `menutype`='kunenamenu';";
			$this->db->setQuery ( $query );
			$moduleid = ( int ) $this->db->loadResult ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		}

		// Forum
		$query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menu['link'])} AND `menutype`='kunenamenu';";
		$this->db->setQuery ( $query );
		$parentid = ( int ) $this->db->loadResult ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		if (! $parentid) {
			$params = new JParameter('');
			$params->bind($menu['params']);
			$query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES
							($parentid, 'kunenamenu', {$this->db->quote($menu['name'])}, {$this->db->quote($menu['alias'])}, {$this->db->quote($menu['link'])}, 'component', 1, 0, $component_id, 0, 1, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);";
			$this->db->setQuery ( $query );
			$this->db->query ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
			$parentid = ( int ) $this->_db->insertId ();
		}

		// Submenu (shown in Kunena)
		$defaultmenu = 0;
		$ordering = 0;
		foreach ($submenu as $menuitem) {
			$ordering++;
//			$query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menuitem['link'])} AND `menutype`='kunenamenu';";
//			$this->db->setQuery ( $query );
//			$id = ( int ) $this->db->loadResult ();
//			if ($this->db->getErrorNum ())
//				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
			$id = 0;
			if (! $id) {
				$params = new JParameter('');
				$params->bind($menuitem['params']);
				$query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES
								($id, 'kunenamenu', {$this->db->quote($menuitem['name'])}, {$this->db->quote($menuitem['alias'])}, {$this->db->quote($menuitem['link'])},'component', 1, $parentid, $component_id, 1, $ordering, 0, '0000-00-00 00:00:00', 0, 0, {$menuitem['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);";
				$this->db->setQuery ( $query );
				$this->db->query ();
				if ($this->db->getErrorNum ())
					throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
				$id = ( int ) $this->_db->insertId ();
				if (!$defaultmenu || (isset($menuitem['default']) && $config->fbdefaultpage == $menuitem['default'])) {
					$defaultmenu = $id;
				}
			}
		}
		if ($defaultmenu) {
			$query = "UPDATE `#__menu` SET `link`={$this->db->quote($menu['link']."&defaultmenu=$defaultmenu")} WHERE id={$parentid}";
			$this->db->setQuery ( $query );
			$this->db->query ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		}

		$query = "SELECT id FROM `#__modules` WHERE `position`='kunena_menu';";
		$this->db->setQuery ( $query );
		$moduleid = ( int ) $this->db->loadResult ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

		// Check if it exists, if not create it
		if (! $moduleid) {
			// Create a module for the Kunena menu
			$query = "REPLACE INTO `#__modules` (`id`, `title`, `content`, `ordering`, `position`, `checked_out`, `checked_out_time`, `published`, `module`, `numnews`, `access`, `showtitle`, `params`, `iscore`, `client_id`, `control`) VALUES
					($moduleid, {$this->db->quote(JText::_ ( 'COM_KUNENA_MENU_TITLE' ))}, '', 0, 'kunena_menu', 0, '0000-00-00 00:00:00', 1, 'mod_mainmenu', 0, 0, 0, 'menutype=kunenamenu\nmenu_style=list\nstartLevel=1\nendLevel=2\nshowAllChildren=1\nwindow_open=\nshow_whitespace=0\ncache=1\ntag_id=\nclass_sfx=\nmoduleclass_sfx=\nmaxdepth=10\nmenu_images=0\nmenu_images_align=0\nmenu_images_link=0\nexpand_menu=0\nactivate_parent=0\nfull_active_id=0\nindent_image=0\nindent_image1=\nindent_image2=\nindent_image3=\nindent_image4=\nindent_image5=\nindent_image6=\nspacer=\nend_spacer=\n\n', 0, 0, '');";
			$this->db->setQuery ( $query );
			$this->db->query ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

			// Now get the module id again, we need it, in order to publish the menu module
			$query = "SELECT id FROM `#__modules` WHERE `position`='kunena_menu';";
			$this->db->setQuery ( $query );
			$moduleid = ( int ) $this->db->loadResult ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );

			// Now publish the module
			$query = "REPLACE INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ($moduleid, 0);";
			$this->db->setQuery ( $query );
			$this->db->query ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		}

		// Finally add forum menu link to default menu
		$jmenu = JMenu::getInstance('site');
		$dmenu = $jmenu->getDefault();
		$query = "SELECT id, name, type, link, published FROM `#__menu` WHERE `alias` IN ('forum', 'kunenaforum', {$this->db->quote(JText::_ ( 'COM_KUNENA_MENU_FORUM_ALIAS' ))}) AND `menutype`={$this->db->quote($dmenu->menutype)}";
		$this->db->setQuery ( $query, 0, 1 );
		$menualias = $this->db->loadObject ();
		if ($this->db->getErrorNum ())
			throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		// We do not want to replace users own menu items (just alias or deprecated link to Kunena)
		if (!$menualias || $menualias->type == 'menulink' || $menualias->link == 'index.php?option=com_kunena') {
			$id = $menualias ? intval($menualias->id) : 0;
			// Keep state (default=unpublished) and name (default=Forum)
			$published = $menualias ? intval($menualias->published) : 0;
			$name = $menualias ? $menualias->name : $menu['name'];
			$query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES
						($id, {$this->db->quote($dmenu->menutype)}, {$this->db->quote($name)}, 'kunenaforum', 'index.php?Itemid={$parentid}', 'menulink', {$published}, 0, 0, 0, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, 'menu_item=$parentid{$menu['params']}\r\n\r\n', 0, 0, 0);";
			$this->db->setQuery ( $query );
			$this->db->query ();
			if ($this->db->getErrorNum ())
				throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () );
		}
		require_once (JPATH_ADMINISTRATOR . '/components/com_menus/helpers/helper.php');
		MenusHelper::cleanCache ();
	}
Ejemplo n.º 16
0
 /**
  * Edit a form
  */
 function edit()
 {
     $user =& JFactory::getUser();
     $session =& JFactory::getSession();
     $db =& JFactory::getDBO();
     $lists = array();
     $row =& JTable::getInstance('form', 'Table');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $row->load($cid[0]);
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     $model = JModel::getInstance('Form', 'FabrikModel');
     $model->setId($cid[0]);
     $model->getTable();
     $groupModels =& $model->getGroupsHiarachy();
     $possible_email_receipt_fields[] = JHTML::_('select.option', '', 'n/a');
     foreach ($groupModels as $groupModel) {
         $groupModel->_form =& $model;
         $elementModels =& $groupModel->getMyElements();
         foreach ($elementModels as $elementModel) {
             if ($elementModel->isReceiptElement()) {
                 $element =& $elementModel->getElement();
                 $possible_email_receipt_fields[] = JHTML::_('select.option', $element->name, $element->label);
             }
         }
     }
     // get params definitions
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'form.xml');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'form.php';
     // get a list of used groups
     $sql = "SELECT  #__fabrik_formgroup.group_id AS value,\n\t\t\t#__fabrik_groups.name AS text\n\t\t\tFROM #__fabrik_formgroup\n\t\t\tLEFT JOIN #__fabrik_groups\n\t\t\tON #__fabrik_formgroup.group_id = #__fabrik_groups.id\n\t\t\tWHERE  #__fabrik_formgroup.form_id = '" . $cid[0] . "'\n\t\t\tAND #__fabrik_groups.name <> ''\n\t\t\tORDER BY  #__fabrik_formgroup.ordering";
     $db->setQuery($sql);
     $current_groups = $db->loadObjectList();
     $lists['current_groups'] = $current_groups;
     $lists['current_grouplist'] = JHTML::_('select.genericlist', $current_groups, 'current_groups', "class=\"inputbox\" style=\"width:100%;\" size=\"10\" ", 'value', 'text', '/');
     // get a list of available groups - need to make the sql only return groups not already listed in mos_fabrik_fromgroup for $id
     //$$$ only unused groups can be assigned now - simplifies a load of stuff for us!
     $db->setQuery("SELECT DISTINCT(group_id) FROM #__fabrik_formgroup");
     $usedgroups = $db->loadResultArray();
     if (!empty($usedgroups)) {
         $db->setQuery("SELECT id AS value, name AS text FROM #__fabrik_groups WHERE id NOT IN(" . implode(",", $usedgroups) . ") ORDER BY `text`");
         $groups = $db->loadObjectList();
     } else {
         $groups = array();
     }
     $lists['groups'] = $groups;
     $lists['grouplist'] = JHTML::_('select.genericlist', $groups, 'groups', "class=\"inputbox\" size=\"10\" style=\"width:100%;\" ", 'value', 'text', null);
     if ($cid[0] != 0) {
         $row->_database_name = $model->getTableName();
         $row->_connection_id = $model->getListModel()->getTable()->connection_id;
     } else {
         //this is a new form so fill in some default values
         $row->error = JText::_('SOME OF THE FORM DATA IS MISSING');
         $row->submit_button_label = JText::_('SUBMIT');
         $row->_database_name = '';
         $row->_connection_id = '';
         $menus = array();
     }
     //get the view only templates
     $viewTemplate = $row->view_only_template == '' ? "default" : $row->view_only_template;
     $lists['viewOnlyTemplates'] = FabrikHelperAdminHTML::templateList('form', 'view_only_template', $viewTemplate);
     //get the form templates
     $formTemplate = $row->form_template == '' ? "default" : $row->form_template;
     $lists['formTemplates'] = FabrikHelperAdminHTML::templateList('form', 'form_template', $formTemplate);
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('form');
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'form.xml');
     $form->bind($row);
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('Never'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     $form->loadINI($row->attribs);
     $session->set('com_fabrik.admin.form.edit.model', $model);
     FabrikViewForm::edit($row, $pluginManager, $lists, $params, $form);
 }
Ejemplo n.º 17
0
 /**
  * Displays Kunena Forum view/layout inside your extension.
  *
  * <code>
  *
  * </code>
  *
  * @param unknown_type $viewName Name of the view.
  * @param unknown_type $layout Name of the layout.
  * @param unknown_type $template Name of the template file.
  * @param unknown_type $params Extra parameters to control the model.
  */
 public static function display($viewName, $layout = 'default', $template = null, $params = array())
 {
     // Filter input
     $viewName = preg_replace('/[^A-Z0-9_]/i', '', $viewName);
     $layout = preg_replace('/[^A-Z0-9_]/i', '', $layout);
     $template = preg_replace('/[^A-Z0-9_]/i', '', $template);
     $template = $template ? $template : null;
     $view = "KunenaView{$viewName}";
     $model = "KunenaModel{$viewName}";
     // Load potentially needed language files
     KunenaFactory::loadLanguage();
     KunenaFactory::loadLanguage('com_kunena.model');
     KunenaFactory::loadLanguage('com_kunena.view');
     require_once KPATH_SITE . '/views/common/view.html.php';
     require_once KPATH_SITE . '/models/common.php';
     if (!class_exists($view)) {
         $vpath = KPATH_SITE . '/views/' . $viewName . '/view.html.php';
         if (!is_file($vpath)) {
             return;
         }
         require_once $vpath;
     }
     if ($viewName != 'common' && !class_exists($model)) {
         $mpath = KPATH_SITE . '/models/' . $viewName . '.php';
         if (!is_file($mpath)) {
             return;
         }
         require_once $mpath;
     }
     $view = new $view(array('base_path' => KPATH_SITE));
     if ($params instanceof JRegistry) {
         // Do nothing
     } elseif (version_compare(JVERSION, '1.6', '>')) {
         // Joomla 1.6+
         $params = new JRegistry($params);
     } else {
         // Joomla 1.5
         $parameters = new JParameter('');
         $parameters->bind($params);
         $params = $parameters;
     }
     $params->set('layout', $layout);
     // Push the model into the view (as default).
     $model = new $model();
     $model->initialize($params);
     $view->setModel($model, true);
     // Add template path
     if ($params->get('templatepath')) {
         $view->addTemplatePath($params->get('templatepath'));
     }
     if ($viewName != 'common') {
         $view->common = new KunenaViewCommon(array('base_path' => KPATH_SITE));
         $view->common->embedded = true;
     }
     // Flag view as being embedded
     $view->embedded = true;
     // Render the view.
     $view->displayLayout($layout, $template);
 }
Ejemplo n.º 18
0
 function getTemplateParams()
 {
     $template = new CTemplateHelper();
     $defaultParam = $template->getTemplatePath('params.ini', 'default');
     $templateParam = $template->getTemplatePath('params.ini');
     $overrideParam = $template->getOverrideTemplatePath('params.ini');
     $params = new JParameter('');
     if (JFile::exists($defaultParam)) {
         $params->bind(JFile::read($defaultParam));
     }
     if (JFile::exists($templateParam)) {
         $params->bind(JFile::read($templateParam));
     }
     if (JFile::exists($overrideParam)) {
         $params->bind(JFile::read($overrideParam));
     }
     return $params;
 }
Ejemplo n.º 19
0
 /**
  * Convert JSON data to JParameter Object
  * @param $data JSON data
  */
 public static function toObject($data)
 {
     $param = new JParameter('');
     $param->bind($data);
     return $param->toObject();
 }