Exemplo n.º 1
0
 /**
  * Ajax load drop down of all columns in a given table
  *
  * @return  null
  */
 public function ajax_loadTableDropDown()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $conn = $input->getInt('conn', 1);
     $oCnn = JModelLegacy::getInstance('Connection', 'FabrikFEModel');
     $oCnn->setId($conn);
     $oCnn->getConnection();
     $db = $oCnn->getDb();
     $table = $input->get('table', '');
     $fieldNames = array();
     $name = $input->get('name', 'jform[params][table_key][]', '', 'string');
     if ($table != '') {
         $table = FabrikString::safeColName($table);
         $sql = 'DESCRIBE ' . $table;
         $db->setQuery($sql);
         $aFields = $db->loadObjectList();
         if (is_array($aFields)) {
             foreach ($aFields as $oField) {
                 $fieldNames[] = JHTML::_('select.option', $oField->Field);
             }
         }
     }
     $fieldDropDown = JHTML::_('select.genericlist', $fieldNames, $name, "class=\"inputbox\"  size=\"1\" ", 'value', 'text', '');
     echo $fieldDropDown;
 }
Exemplo n.º 2
0
 /**
  * Clone the record
  *
  * @return  bool
  */
 private function _process()
 {
     $params = $this->getParams();
     /** @var FabrikFEModelForm $formModel */
     $formModel = $this->getModel();
     $clone_times_field_id = $params->get('clone_times_field', '');
     $clone_batchid_field_id = $params->get('clone_batchid_field', '');
     if ($clone_times_field_id != '') {
         $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id);
         $element = $elementModel->getElement(true);
         if ($clone_batchid_field_id != '') {
             $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id);
             $id_element = $elementModel->getElement(true);
             $formModel->formData[$id_element->name] = $formModel->fullFormData['rowid'];
             $formModel->formData[$id_element->name . '_raw'] = $formModel->fullFormData['rowid'];
             $listModel = $formModel->getlistModel();
             $listModel->setFormModel($formModel);
             $primaryKey = FabrikString::shortColName($listModel->getPrimaryKey());
             $formModel->formData[$primaryKey] = $formModel->fullFormData['rowid'];
             $formModel->formData[$primaryKey . '_raw'] = $formModel->fullFormData['rowid'];
             $listModel->storeRow($formModel->formData, $formModel->fullFormData['rowid']);
         }
         $clone_times = $formModel->formData[$element->name];
         if (is_numeric($clone_times)) {
             $clone_times = (int) $clone_times;
             $formModel->formData['Copy'] = 1;
             for ($x = 1; $x < $clone_times; $x++) {
                 $formModel->processToDB();
             }
             return true;
         }
     }
     throw new RuntimeException("Couldn't find a valid number of times to clone!");
 }
Exemplo n.º 3
0
 /**
  * create the pivot data
  * @return array of objects - first being the headings, subsequent the data
  */
 public function getPivot()
 {
     $model = $this->formModel->getTableModel();
     $params =& $model->getParams();
     $val = FabrikString::safeColName($params->get('pivot_value', ''));
     $xCol = FabrikString::safeColName($params->get('pivot_xcol', ''));
     $yCol = FabrikString::safeColName($params->get('pivot_ycol', ''));
     $db =& $model->getDb();
     $table =& $model->getTable();
     $join = $model->_buildQueryJoin();
     $where = $model->_buildQueryWhere();
     $db->setQuery("SELECT DISTINCT {$yCol} FROM {$table->db_table_name}");
     $yCols = $db->loadResultArray();
     $query = "select name,\n";
     $data = array();
     foreach ($yCols as $c) {
         $data[] = "SUM({$val}*(1-abs(sign(" . $yCol . "-" . $c . ")))) as exam" . $c . "\n";
     }
     $query .= implode(",", $data);
     $query .= "\nFROM " . $table->db_table_name . " {$join} {$where} group by {$xCol}";
     $db->setQuery($query);
     $data = $db->loadObjectList();
     $headings = JArrayHelper::toObject(array_keys(JArrayHelper::fromObject($data[0])));
     array_unshift($data, $headings);
     return $data;
 }
Exemplo n.º 4
0
 /**
  * validate the elements data against the rule
  * @param string data to check
  * @param object element Model
  * @param int plugin sequence ref
  * @return bol true if validation passes, false if fails
  */
 function validate($data, &$elementModel, $c)
 {
     //could be a dropdown with multivalues
     if (is_array($data)) {
         $data = implode('', $data);
     }
     $params = $this->getParams();
     $element = $elementModel->getElement();
     $listModel = $elementModel->getlistModel();
     $table = $listModel->getTable();
     $db = $listModel->getDb();
     $lookuptable = $db->NameQuote($table->db_table_name);
     $data = $db->Quote($data);
     $query = $db->getQuery(true);
     $cond = $params->get('isuniquevalue-caseinsensitive') == 1 ? 'LIKE' : '=';
     $query->select('COUNT(*)')->from($lookuptable)->where($element->name . ' ' . $cond . ' ' . $data);
     // $$$ hugh - need to check to see if we're editing a record, otherwise
     // will fail 'cos it finds the original record (assuming this element hasn't changed)
     // @TODO - is there a better way getting the rowid?  What if this is form a joined table?
     // $rowid = JRequest::getVar('rowid');
     // Have to do it by grabbing PK from request, 'cos rowid isn't set on AJAX validation
     $pk = FabrikString::safeColNameToArrayKey($table->db_primary_key);
     $rowid = JRequest::getVar($pk, '');
     if (!empty($rowid)) {
         $query->where($table->db_primary_key . ' != ' . $db->Quote($rowid));
     }
     $db->setQuery($query);
     $c = $db->loadResult();
     return $c == 0 ? true : false;
 }
Exemplo n.º 5
0
 /**
  * return the javascript to create an instance of the class defined in formJavascriptClass
  * @param object parameters
  * @param list table model
  * @param array [0] => string table's form id to contain plugin
  * @return bool
  */
 function onLoadJavascriptInstance($params, $model, $args)
 {
     parent::onLoadJavascriptInstance($params, $model, $args);
     FabrikHelperHTML::script('media/com_fabrik/js/element.js');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     $listModel->setId(JRequest::getVar('listid'));
     $elements = $model->getElements('safecolname');
     $pels = $params->get('inline_editable_elements');
     $use = json_decode($pels);
     if (!is_object($use)) {
         $aEls = trim($pels) == '' ? array() : explode(",", $pels);
         $use = new stdClass();
         foreach ($aEls as $e) {
             $use->{$e} = array($e);
         }
     }
     $els = array();
     $srcs = array();
     $test = (array) $use;
     if (!empty($test)) {
         foreach ($use as $key => $fields) {
             $trigger = $elements[$key];
             $els[$key] = new stdClass();
             $els[$key]->elid = $trigger->_id;
             $els[$key]->plugins = array();
             foreach ($fields as $field) {
                 $val = $elements[$field];
                 //load in all element js classes
                 if (is_object($val)) {
                     $val->formJavascriptClass($srcs);
                     $els[$key]->plugins[$field] = $val->getElement()->id;
                 }
             }
         }
     } else {
         foreach ($elements as $key => $val) {
             $key = FabrikString::safeColNameToArrayKey($key);
             $els[$key] = new stdClass();
             $els[$key]->elid = $val->_id;
             $els[$key]->plugins = array();
             $els[$key]->plugins[$key] = $val->getElement()->id;
             //load in all element js classes
             $val->formJavascriptClass($srcs);
         }
     }
     FabrikHelperHTML::script($srcs);
     $opts = $this->getElementJSOptions($model);
     $opts->elements = $els;
     $opts->formid = $model->getFormModel()->getId();
     $opts->focusClass = 'focusClass';
     $opts->editEvent = $params->get('inline_edit_event', 'dblclick');
     $opts->tabSave = $params->get('inline_tab_save', false);
     $opts->showCancel = $params->get('inline_show_cancel', true);
     $opts->showSave = (bool) $params->get('inline_show_save', true);
     $opts->loadFirst = (bool) $params->get('inline_load_first', false);
     $opts = json_encode($opts);
     $formid = 'list_' + $model->getFormModel()->getForm()->id;
     $this->jsInstance = "new FbListInlineEdit({$opts})";
     return true;
 }
Exemplo n.º 6
0
 /**
  * Clone the record
  *
  * @param   object  $params      plugin params
  * @param   object  &$formModel  form model
  *
  * @return  bool
  */
 private function _process($params, &$formModel)
 {
     $clone_times_field_id = $params->get('clone_times_field', '');
     $clone_batchid_field_id = $params->get('clone_batchid_field', '');
     if ($clone_times_field_id != '') {
         $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id);
         $element = $elementModel->getElement(true);
         if ($clone_batchid_field_id != '') {
             $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id);
             $id_element = $id_elementModel->getElement(true);
             $formModel->_formData[$id_element->name] = $formModel->_fullFormData['rowid'];
             $formModel->_formData[$id_element->name . '_raw'] = $formModel->_fullFormData['rowid'];
             $listModel = $formModel->getlistModel();
             $listModel->_oForm = $formModel;
             $primaryKey = FabrikString::shortColName($listModel->getTable()->db_primary_key);
             $formModel->_formData[$primaryKey] = $formModel->_fullFormData['rowid'];
             $formModel->_formData[$primaryKey . '_raw'] = $formModel->_fullFormData['rowid'];
             $listModel->storeRow($formModel->_formData, $formModel->_fullFormData['rowid']);
         }
         // $clone_times_field = $elementModel->getFullName(false, true, false);
         $clone_times = $formModel->_formData[$element->name];
         if (is_numeric($clone_times)) {
             $clone_times = (int) $clone_times;
             $formModel->_formData['Copy'] = 1;
             for ($x = 1; $x < $clone_times; $x++) {
                 $formModel->processToDB();
             }
             return true;
         }
     }
     JError::raiseNotice(JText::_('CLONEERR'), "Couldn't find a valid number of times to clone!");
     return true;
 }
Exemplo n.º 7
0
 /**
  * Return the javascript to create an instance of the class defined in formJavascriptClass
  *
  * @param   array  $args  Array [0] => string table's form id to contain plugin
  *
  * @return bool
  */
 public function onLoadJavascriptInstance($args)
 {
     if (!$this->canUse()) {
         return;
     }
     /** @var FabrikFEModelList $model */
     $model = $this->getModel();
     $params = $this->getParams();
     $orderEl = $model->getFormModel()->getElement($params->get('order_element'), true);
     $opts = $this->getElementJSOptions();
     $orderElName = FabrikString::safeColNameToArrayKey(FArrayHelper::getValue($model->orderEls, 0, ''));
     $opts->enabled = $orderElName == FabrikString::safeColNameToArrayKey($orderEl->getOrderByName()) ? true : false;
     $opts->listid = $model->getId();
     $opts->orderElementId = $params->get('order_element');
     $opts->handle = $params->get('order_element_as_handle', 1) == 1 ? '.' . $orderEl->getOrderByName() : false;
     $opts->direction = $opts->enabled ? $model->orderDirs[0] : '';
     $opts->transition = '';
     $opts->duration = '';
     $opts->constrain = '';
     $opts->clone = '';
     $opts->revert = '';
     $opts = json_encode($opts);
     $this->jsInstance = "new FbListOrder({$opts})";
     return true;
 }
Exemplo n.º 8
0
 /**
  * return the javascript to create an instance of the class defined in formJavascriptClass
  * @param object parameters
  * @param object table model
  * @param array [0] => string table's form id to contain plugin
  * @return bool
  */
 function loadJavascriptInstance($params, $model, $args)
 {
     if (!$this->canUse()) {
         return;
     }
     $form_id = $args[0];
     FabrikHelperHTML::script('element.js', 'media/com_fabrik/js/');
     $orderEl = $model->getForm()->getElement($params->get('order_element'), true);
     $opts = new stdClass();
     $opts->enabled = count($model->orderEls) === 1 && FabrikString::safeColNameToArrayKey($model->orderEls[0]) == FabrikString::safeColNameToArrayKey($orderEl->getOrderByName()) ? true : false;
     $opts->liveSite = COM_FABRIK_LIVESITE;
     $opts->tableid = $model->_id;
     $opts->orderElementId = $params->get('order_element');
     $opts->handle = $params->get('order_element_as_handle', 1) == 1 ? '.fabrik_row___' . $orderEl->getOrderByName() : false;
     $opts->direction = $opts->enabled ? $model->orderDirs[0] : '';
     $opts->transition = '';
     $opts->duration = '';
     $opts->constrain = '';
     $opts->clone = '';
     $opts->revert = '';
     $opts->container = 'table_' . $model->getTable()->id;
     $opts = json_encode($opts);
     $lang = $this->_getLang();
     $lang = json_encode($lang);
     $this->jsInstance = "new FbTableOrder('{$form_id}', {$opts}, {$lang})";
     return true;
 }
Exemplo n.º 9
0
 /**
  * Tagify a string
  *
  * @param   string  $data  Tagify
  *
  * @return  string	Tagified string
  */
 protected function tagify($data)
 {
     $name = $this->getFullName(true, false);
     $params = $this->getParams();
     $listModel = $this->getlistModel();
     $filters = $listModel->getFilterArray();
     $fkeys = JArrayHelper::getValue($filters, 'key', array());
     $data = explode(",", strip_tags($data));
     $tags = array();
     $url = $params->get('textarea_tagifyurl');
     if ($url == '') {
         $url = $_SERVER['REQUEST_URI'];
         $bits = explode('?', $url);
         $root = JArrayHelper::getValue($bits, 0, '', 'string');
         $bits = JArrayHelper::getValue($bits, 1, '', 'string');
         $bits = explode("&", $bits);
         $fullName = $this->getFullName(true, false);
         for ($b = count($bits) - 1; $b >= 0; $b--) {
             $parts = explode("=", $bits[$b]);
             if (count($parts) > 1) {
                 $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&');
                 if ($key == $fullName) {
                     unset($bits[$b]);
                 }
                 if ($key == $fullName . '[value]') {
                     unset($bits[$b]);
                 }
                 if ($key == $fullName . '[condition]') {
                     unset($bits[$b]);
                 }
             }
         }
     }
     $url = $root . '?' . implode('&', $bits);
     // $$$ rob 24/02/2011 remove duplicates from tags
     $data = array_unique($data);
     $img = FabrikWorker::j3() ? 'bookmark.png' : 'tag.png';
     $icon = FabrikHelperHTML::image($img, 'form', @$this->tmpl, array('alt' => 'tag'));
     foreach ($data as $d) {
         $d = trim($d);
         if ($d != '') {
             if (trim($params->get('textarea_tagifyurl')) == '') {
                 $qs = strstr($url, '?');
                 if (substr($url, -1) === '?') {
                     $thisurl = $url . $name . '[value]=' . $d;
                 } else {
                     $thisurl = strstr($url, '?') ? $url . '&' . $name . '[value]=' . urlencode($d) : $url . '?' . $name . '[value]=' . urlencode($d);
                 }
                 $thisurl .= '&' . $name . '[condition]=CONTAINS';
                 $thisurl .= '&resetfilters=1';
             } else {
                 $thisurl = str_replace('{tag}', urlencode($d), $url);
             }
             $tags[] = '<a href="' . $thisurl . '" class="fabrikTag">' . $icon . $d . '</a>';
         }
     }
     return implode(' ', $tags);
 }
Exemplo n.º 10
0
 /**
  * Internally render the plugin, and add required script declarations
  * to the document
  *
  * @return  void
  */
 public function render()
 {
     $params = $this->getParams();
     $document = JFactory::getDocument();
     $document->addScript("http://api.simile-widgets.org/runway/1.0/runway-api.js");
     $c = 0;
     $images = (array) $params->get('coverflow_image');
     $titles = (array) $params->get('coverflow_title');
     $subtitles = (array) $params->get('coverflow_subtitle');
     $listIds = (array) $params->get('coverflow_table');
     $eventData = array();
     foreach ($listIds as $listId) {
         $listModel = JModelLegacy::getInstance('List', 'FabrikFEModel');
         $listModel->setId($listId);
         $list = $listModel->getTable();
         $listModel->getPagination(0, 0, 0);
         $image = $images[$c];
         $title = $titles[$c];
         $subtitle = $subtitles[$c];
         $data = $listModel->getData();
         if ($listModel->canView() || $listModel->canEdit()) {
             $elements = $listModel->getElements();
             $imageElement = FArrayHelper::getValue($elements, FabrikString::safeColName($image));
             foreach ($data as $group) {
                 if (is_array($group)) {
                     foreach ($group as $row) {
                         $event = new stdClass();
                         if (!method_exists($imageElement, 'getStorage')) {
                             switch (get_class($imageElement)) {
                                 case 'FabrikModelFabrikImage':
                                     $rootFolder = $imageElement->getParams()->get('selectImage_root_folder');
                                     $rootFolder = JString::ltrim($rootFolder, '/');
                                     $rootFolder = JString::rtrim($rootFolder, '/');
                                     $event->image = COM_FABRIK_LIVESITE . 'images/stories/' . $rootFolder . '/' . $row->{$image . '_raw'};
                                     break;
                                 default:
                                     $event->image = isset($row->{$image . '_raw'}) ? $row->{$image . '_raw'} : '';
                                     break;
                             }
                         } else {
                             $event->image = $imageElement->getStorage()->pathToURL($row->{$image . '_raw'});
                         }
                         $event->title = $title === '' ? '' : (string) strip_tags($row->{$title});
                         $event->subtitle = $subtitle === '' ? '' : (string) strip_tags($row->{$subtitle});
                         $eventData[] = $event;
                     }
                 }
             }
         }
         $c++;
     }
     $json = json_encode($eventData);
     $str = "var coverflow = new FbVisCoverflow({$json});";
     $srcs = FabrikHelperHTML::framework();
     $srcs['Coverflow'] = $this->srcBase . 'coverflow/coverflow.js';
     FabrikHelperHTML::script($srcs, $str);
 }
Exemplo n.º 11
0
 function getOptions()
 {
     $db = FabrikWorker::getDbo(true);
     $query = $db->getQuery(true);
     $query->select("id AS value, label AS " . FabrikString::safeColName('text'));
     $query->from("#__{package}_forms");
     $query->order("value DESC");
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     return $rows;
 }
Exemplo n.º 12
0
 /**
  * Does a file exist
  *
  * @param   string  $filepath  File path to test
  *
  * @return bool
  */
 public function exists($filepath)
 {
     if ($filepath == '\\') {
         return false;
     }
     if (JFile::exists($filepath)) {
         return true;
     }
     $filepath = COM_FABRIK_BASE . '/' . FabrikString::ltrimword($filepath, COM_FABRIK_BASE . '/');
     return JFile::exists($filepath);
 }
Exemplo n.º 13
0
 /**
  * Run right at the end of the form processing
  * form needs to be set to record in database for this to hook to be called
  *
  * @return	bool
  */
 public function onAfterProcess()
 {
     $params = $this->getParams();
     $input = $this->app->input;
     $formModel = $this->getModel();
     if ($params->get('ask-receipt')) {
         if (!array_key_exists('fabrik_email_copy', $_POST)) {
             return;
         }
     }
     $rowId = $input->get('rowid');
     $config = JFactory::getConfig();
     $w = new FabrikWorker();
     $data = $this->getProcessData();
     $message = $params->get('receipt_message');
     $editURL = COM_FABRIK_LIVESITE . "index.php?option=com_" . $this->package . "&amp;view=form&amp;fabrik=" . $formModel->get('id') . "&amp;rowid=" . $rowId;
     $viewURL = COM_FABRIK_LIVESITE . "index.php?option=com_" . $this->package . "&amp;view=details&amp;fabrik=" . $formModel->get('id') . "&amp;rowid=" . $rowId;
     $editLink = "<a href=\"{$editURL}\">" . FText::_('EDIT') . "</a>";
     $viewLink = "<a href=\"{$viewURL}\">" . FText::_('VIEW') . "</a>";
     $message = str_replace('{fabrik_editlink}', $editLink, $message);
     $message = str_replace('{fabrik_viewlink}', $viewLink, $message);
     $message = str_replace('{fabrik_editurl}', $editURL, $message);
     $message = str_replace('{fabrik_viewurl}', $viewURL, $message);
     $message = $w->parseMessageForPlaceHolder($message, $data, false);
     $to = $w->parseMessageForPlaceHolder($params->get('receipt_to'), $data, false);
     $to = FabrikString::stripSpace($to);
     if (empty($to)) {
         /* $$$ hugh - not much point trying to send if we don't have a To address
          * (happens frequently if folk don't properly validate their form inputs and are using placeholders)
          * @TODO - might want to add some feedback about email not being sent
          */
         return;
     }
     $to = explode(',', $to);
     $subject = html_entity_decode($params->get('receipt_subject', ''));
     $subject = JText::_($w->parseMessageForPlaceHolder($subject, $data, false));
     $from = $config->get('mailfrom', '');
     $fromName = $config->get('fromname', '');
     // Darn silly hack for poor joomfish settings where lang parameters are set to override joomla global config but not mail translations entered
     $rawConfig = new JConfig();
     if ($from === '') {
         $from = $rawConfig->mailfrom;
     }
     if ($fromName === '') {
         $fromName = $rawConfig->fromname;
     }
     $from = $params->get('from_email', $from);
     $res = FabrikWorker::sendMail($from, $fromName, $to, $subject, $message, true);
     if (!$res) {
         throw new RuntimeException('Couldn\'t send receipt', 500);
     }
 }
Exemplo n.º 14
0
 /**
  * Does a file exist
  *
  * @param   string  $filepath     File path to test
  * @param   bool    $prependRoot  also test with root prepended
  *
  * @return bool
  */
 public function exists($filepath, $prependRoot = true)
 {
     if (empty($filepath) || $filepath == '\\') {
         return false;
     }
     if (JFile::exists($filepath)) {
         return true;
     }
     if ($prependRoot) {
         $filepath = COM_FABRIK_BASE . '/' . FabrikString::ltrimword($filepath, COM_FABRIK_BASE . '/');
         return JFile::exists($filepath);
     }
     return false;
 }
Exemplo n.º 15
0
 /**
  * (non-PHPdoc)
  * @see components/com_fabrik/models/FabrikModelElement::_buildFilterJoin()
  */
 protected function filterValueList_Exact($normal, $tableName = '', $label = '', $id = '', $incjoin = true)
 {
     $tableModel = $this->getTableModel();
     $fabrikDb =& $tableModel->getDb();
     $table =& $tableModel->getTable();
     $elName2 = $this->getFullName(false, false, false);
     $ids = $tableModel->getColumnData($elName2);
     $elName = FabrikString::safeColName($this->getFullName(false, true, false));
     $sql = 'SELECT name AS ' . $fabrikDb->nameQuote('text') . ', id AS ' . $fabrikDb->nameQuote('value') . ' from #__core_acl_aro_groups ' . "WHERE id IN ('" . implode("','", $ids) . "')";
     $fabrikDb->setQuery($sql);
     $rows = $fabrikDb->loadObjectList();
     $this->nameMap($rows);
     return $rows;
 }
Exemplo n.º 16
0
 /**
  * Get list options
  *
  * @return  array
  */
 protected function getOptions()
 {
     $db = FabrikWorker::getDbo();
     $query = $db->getQuery(true);
     $query->select("id AS value, CONCAT(label, '(', version , ')') AS " . FabrikString::safeColName(text));
     $query->from('#__{package}_packages');
     $query->order('value DESC');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $o = new stdClass();
     $o->value = 0;
     $o->text = JText::_('COM_FABRIK_NO_PACKAGE');
     array_unshift($rows, $o);
     return $rows;
 }
Exemplo n.º 17
0
 function onCanSelectRow($params, $tableModel, $row)
 {
     // If $row is null, we were called from the table's canEdit() in a per-table rather than per-row context,
     // and we don't have an opinion on per-table edit permissions, so just return true.
     if (!is_object($row[0])) {
         return true;
     }
     $field = $params->get('canselectrow_field');
     $field = FabrikString::safeColnameToArrayKey($field);
     // $$$ rob if no can edit field selected in admin return true
     if (trim($field) == '') {
         return true;
     }
     $value = $params->get('canselectrow_value');
     return $row[0]->{$field} == $value;
 }
Exemplo n.º 18
0
 function _strToCoords($v, $zoomlevel = 0)
 {
     $o = new stdClass();
     $o->coords = array('', '');
     $o->zoomlevel = (int) $zoomlevel;
     if (strstr($v, ",")) {
         $ar = explode(":", $v);
         $o->zoomlevel = count($ar) == 2 ? array_pop($ar) : 4;
         $v = FabrikString::ltrimword($ar[0], "(");
         $v = rtrim($v, ")");
         $o->coords = explode(",", $v);
     } else {
         $o->coords = array(0, 0);
     }
     return $o;
 }
Exemplo n.º 19
0
 /**
  * tagify a string
  * @param string to tagify
  * @return string tagified string
  */
 protected function tagify($data)
 {
     $name = $this->getFullName(false, true, false);
     $params = $this->getParams();
     $listModel = $this->getlistModel();
     $filters = $listModel->getFilterArray();
     $fkeys = JArrayHelper::getValue($filters, 'key', array());
     $data = explode(",", strip_tags($data));
     $tags = array();
     $url = $params->get('textarea_tagifyurl');
     if ($url == '') {
         $url = $_SERVER['REQUEST_URI'];
         $bits = explode('?', $url);
         $bits = JArrayHelper::getValue($bits, 1, '', 'string');
         $bits = explode("&", $bits);
         foreach ($bits as $bit) {
             $parts = explode("=", $bit);
             if (count($parts) > 1) {
                 $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&');
                 if ($key == $this->getFullName(false, true, false)) {
                     $url = str_replace($key . '=' . $parts[1], '', $url);
                 }
             }
         }
     }
     // $$$ rbo 24/02/2011 remove duplicates from tags
     $data = array_unique($data);
     $icon = FabrikHelperHTML::image('tag.png', 'form', @$this->tmpl, array('alt' => 'tag'));
     foreach ($data as $d) {
         $d = trim($d);
         if ($d != '') {
             if (trim($params->get('textarea_tagifyurl')) == '') {
                 $qs = strstr($url, '?');
                 if (substr($url, -1) === '?') {
                     $thisurl = "{$url}{$name}={$d}";
                 } else {
                     $thisurl = strstr($url, '?') ? "{$url}&{$name}=" . urlencode($d) : "{$url}?{$name}=" . urlencode($d);
                 }
             } else {
                 $thisurl = str_replace('{tag}', urlencode($d), $url);
             }
             $tags[] = '<a href="' . $thisurl . '" class="fabrikTag">' . $icon . $d . '</a>';
         }
     }
     return implode(" ", $tags);
 }
Exemplo n.º 20
0
 /**
  * validate the elements data against the rule
  * @param string data to check
  * @param object element Model
  * @param int plugin sequence ref
  * @param int repeat group count
  * @return bol true if validation passes, false if fails
  */
 function validate($data, &$elementModel, $c, $repeat_count = 0)
 {
     //could be a dropdown with multivalues
     if (is_array($data)) {
         $data = implode('', $data);
     }
     $params =& $this->getParams();
     $element =& $elementModel->getElement();
     $tableModel =& $elementModel->getTableModel();
     $table =& $tableModel->getTable();
     $db =& $tableModel->getDb();
     $lookuptable = $db->nameQuote($table->db_table_name);
     $data = $db->Quote($data);
     if ($params->get('isuniquevalue-caseinsensitive') == 1) {
         $sql = "SELECT COUNT(*) FROM {$lookuptable} WHERE {$element->name} LIKE {$data}";
     } else {
         $sql = "SELECT COUNT(*) FROM {$lookuptable} WHERE {$element->name} = {$data}";
     }
     // $$$ hugh - need to check to see if we're editing a record, otherwise
     // will fail 'cos it finds the original record (assuming this element hasn't changed)
     // @TODO - is there a better way getting the rowid?  What if this is form a joined table?
     // $rowid = JRequest::getVar('rowid');
     // Have to do it by grabbing PK from request, 'cos rowid isn't set on AJAX validation
     $pk = FabrikString::safeColNameToArrayKey($table->db_primary_key);
     $rowid = JRequest::getVar($pk, '');
     if (!empty($rowid)) {
         //if main key is in repeat group!
         if (is_array($rowid)) {
             foreach ($rowid as &$i) {
                 $i = $db->Quote($i);
             }
             $s = implode(',', $rowid);
             if ($s !== "''") {
                 $sql .= " AND {$table->db_primary_key} NOT IN (" . $s . ")";
             }
         } else {
             $sql .= " AND {$table->db_primary_key} != " . $db->Quote($rowid);
         }
     }
     $db->setQuery($sql);
     $c = $db->loadResult();
     return $c == 0 ? true : false;
 }
Exemplo n.º 21
0
	private function _process(&$params, &$formModel )
	{
		$user = JFactory::getUser();
		$db = FabrikWorker::getDbo();
		if ($params->get('limit_allow_anonymous')) {
			return true;
		}
		if (JRequest::getCmd('view') === 'details') {
			return true;
		}

		$listid = (int)$params->get('limit_table');
		if ($listid === 0) {
			//use the limit setting supplied in the admin params
			$limit = (int)$params->get('limit_length');
		} else {
			//look up the limit from the table spec'd in the admin params
			$listModel = JModel::getInstance('List', 'FabrikFEModel');
			$listModel->setId($listid);
			$max = $db->NameQuote(FabrikString::shortColName($params->get('limit_max')));
			$userfield = $db->NameQuote(FabrikString::shortColName($params->get('limit_user')));
			$db->setQuery("SELECT $max FROM " . $listModel->getTable()->db_table_name . " WHERE $userfield = " . (int)$user->get('id'));
			$limit = (int)$db->loadResult();

		}
		$field = $params->get('limit_userfield');
		$listModel = $formModel->getlistModel();
		$list = $listModel->getTable();
		$db = $listModel->getDb();
		$db->setQuery("SELECT COUNT($field) FROM $list->db_table_name WHERE $field = " . (int)$user->get('id'));

		$c = $db->loadResult();
		if ($c >= $limit) {
			$msg = $params->get('limit_reached_message');
			$msg = str_replace('{limit}', $limit, $msg);
			JError::raiseNotice(1, $msg);
			return false;
		} else {
			$app = JFactory::getApplication();
			$app->enqueueMessage(JText::sprintf('ENTRIES_LEFT_MESSAGE', $limit - $c, $limit));
		}
		return true;
	}
Exemplo n.º 22
0
 /**
  * Process the plugin
  *
  * @param   object  $params      plugin params
  * @param   object  &$formModel  form model
  *
  * @return  bool
  */
 private function _process($params, &$formModel)
 {
     $user = JFactory::getUser();
     $db = FabrikWorker::getDbo();
     $query = $db->getQuery(true);
     if ($params->get('limit_allow_anonymous')) {
         return true;
     }
     if (JRequest::getCmd('view') === 'details' || $formModel->getRowId() > 0) {
         return true;
     }
     $listid = (int) $params->get('limit_table');
     if ($listid === 0) {
         // Use the limit setting supplied in the admin params
         $limit = (int) $params->get('limit_length');
     } else {
         // Look up the limit from the table spec'd in the admin params
         $listModel = JModel::getInstance('List', 'FabrikFEModel');
         $listModel->setId($listid);
         $max = $db->quoteName(FabrikString::shortColName($params->get('limit_max')));
         $userfield = $db->quoteName(FabrikString::shortColName($params->get('limit_user')));
         $query->select($max)->from($listModel->getTable()->db_table_name)->where($userfield . ' = ' . (int) $user->get('id'));
         $db->setQuery($query);
         $limit = (int) $db->loadResult();
     }
     $field = $params->get('limit_userfield');
     $listModel = $formModel->getlistModel();
     $list = $listModel->getTable();
     $db = $listModel->getDb();
     $query->clear()->select(' COUNT(' . $field . ')')->from($list->db_table_name)->where($field . ' = ' . (int) $user->get('id'));
     $db->setQuery($query);
     $c = $db->loadResult();
     if ($c >= $limit) {
         $msg = $params->get('limit_reached_message', JText::sprintf('PLG_FORM_LIMIT_LIMIT_REACHED', $limit));
         $msg = str_replace('{limit}', $limit, $msg);
         JError::raiseNotice(1, $msg);
         return false;
     } else {
         $app = JFactory::getApplication();
         $app->enqueueMessage(JText::sprintf('PLG_FORM_LIMIT_ENTRIES_LEFT_MESSAGE', $limit - $c, $limit));
     }
     return true;
 }
Exemplo n.º 23
0
 /**
  * get a list of unused groups
  * @return array list of groups, html list of groups
  */
 public function getGroupList()
 {
     $db = FabrikWorker::getDbo(true);
     $query = $db->getQuery(true);
     $query->select('DISTINCT(group_id)')->from('#__{package}_formgroup');
     $db->setQuery($query);
     $usedgroups = $db->loadResultArray();
     $query = $db->getQuery(true);
     $query->select('id AS value, name AS text')->from('#__{package}_groups');
     if (!empty($usedgroups)) {
         $query->where('id NOT IN(' . implode(",", $usedgroups) . ')');
     }
     $query->where('published <> -2');
     $query->order(FabrikString::safeColName('text'));
     $db->setQuery($query);
     $groups = $db->loadObjectList();
     $list = JHTML::_('select.genericlist', $groups, 'jform[groups]', "class=\"inputbox\" size=\"10\" style=\"width:100%;\" ", 'value', 'text', null, $this->id . '-from');
     return array($groups, $list);
 }
Exemplo n.º 24
0
 /**
  * Return the javascript to create an instance of the class defined in formJavascriptClass
  *
  * @param   object  $params  plugin parameters
  * @param   object  $model   list model
  * @param   array   $args    array [0] => string table's form id to contain plugin
  *
  * @return bool
  */
 public function onLoadJavascriptInstance($params, $model, $args)
 {
     if (!$this->canUse()) {
         return;
     }
     $orderEl = $model->getFormModel()->getElement($params->get('order_element'), true);
     $form_id = $model->getFormModel()->getId();
     $opts = $this->getElementJSOptions($model);
     $opts->enabled = count($model->orderEls) === 1 && FabrikString::safeColNameToArrayKey($model->orderEls[0]) == FabrikString::safeColNameToArrayKey($orderEl->getOrderByName()) ? true : false;
     $opts->listid = $model->getId();
     $opts->orderElementId = $params->get('order_element');
     $opts->handle = $params->get('order_element_as_handle', 1) == 1 ? '.' . $orderEl->getOrderByName() : false;
     $opts->direction = $opts->enabled ? $model->orderDirs[0] : '';
     $opts->transition = '';
     $opts->duration = '';
     $opts->constrain = '';
     $opts->clone = '';
     $opts->revert = '';
     $opts = json_encode($opts);
     $this->jsInstance = "new FbListOrder({$opts})";
     return true;
 }
Exemplo n.º 25
0
 /**
  * get fabrikar.com rss feed
  * @return string
  */
 function getRSSFeed()
 {
     //  get RSS parsed object
     $options = array();
     $options['rssUrl'] = 'http://feeds.feedburner.com/fabrik';
     $options['cache_time'] = 86400;
     $rssDoc =& JFactory::getXMLparser('RSS', $options);
     if ($rssDoc == false) {
         $output = JText::_('Error: Feed not retrieved');
     } else {
         // channel header and link
         $title = $rssDoc->get_title();
         $link = $rssDoc->get_link();
         $output = '<table class="adminlist">';
         $output .= '<tr><th colspan="3"><a href="' . $link . '" target="_blank">' . JText::_($title) . '</th></tr>';
         $items = array_slice($rssDoc->get_items(), 0, 3);
         $numItems = count($items);
         if ($numItems == 0) {
             $output .= '<tr><th>' . JText::_('No news items found') . '</th></tr>';
         } else {
             $k = 0;
             for ($j = 0; $j < $numItems; $j++) {
                 $item = $items[$j];
                 $output .= '<tr><td class="row' . $k . '">';
                 $output .= '<a href="' . $item->get_link() . '" target="_blank">' . $item->get_title() . '</a>';
                 $output .= '<br />' . $item->get_date('Y-m-d');
                 if ($item->get_description()) {
                     $description = FabrikString::truncate($item->get_description(), array('wordcount' => 50));
                     $output .= '<br />' . $description;
                 }
                 $output .= '</td></tr>';
             }
         }
         $k = 1 - $k;
         $output .= '</table>';
     }
     return $output;
 }
Exemplo n.º 26
0
	/**
	 * return the javascript to create an instance of the class defined in formJavascriptClass
	 * @param object parameters
	 * @param list table model
	 * @param array [0] => string table's form id to contain plugin
	 * @return bool
	 */

	function onLoadJavascriptInstance($params, $model, $args)
	{
		parent::onLoadJavascriptInstance($params, $model, $args);
		FabrikHelperHTML::addStyleDeclaration('.focusClass{border:1px solid red !important;}');
		FabrikHelperHTML::script('media/com_fabrik/js/element.js');
		$listModel = JModel::getInstance('list', 'FabrikFEModel');
		$listModel->setId(JRequest::getVar('listid'));

		$elements = $model->getElements('filtername');
		$pels = $params->get('inline_editable_elements');
		$use = trim($pels) == '' ? array() : explode(",", $pels);
		$els = array();
		$srcs = array();
		foreach ($elements as $key => $val) {
			$key = FabrikString::safeColNameToArrayKey($key);
			if (empty($use) || in_array($key, $use)) {
				$els[$key] = new stdClass();
				$els[$key]->elid = $val->_id;
				$els[$key]->plugin = $val->getElement()->plugin;
				//load in all element js classes
				$val->formJavascriptClass($src);
			}
		}
		FabrikHelperHTML::script($srcs, true);
		$opts = new stdClass();
		$opts->elements = $els;
		$opts->listid = $model->getId();
		$opts->focusClass = 'focusClass';
		$opts->editEvent = $params->get('inline_edit_event', 'dblclick');
		$opts->tabSave = $params->get('inline_tab_save', false);
		$opts->showCancel = $params->get('inline_show_cancel', true);
		$opts->showSave = $params->get('inline_show_save', true);
		$opts->loadFirst = (bool)$params->get('inline_load_first', false);
		$opts = json_encode($opts);
		$formid = 'list_'+$model->getFormModel()->getForm()->id;
		$this->jsInstance = "new FbListInlineEdit($opts)";
		return true;
	}
Exemplo n.º 27
0
 protected function decide($v)
 {
     $params =& $this->getParams();
     $ids = (array) $params->get('approvals_table');
     $approveEls = (array) $params->get('approvals_approve_element');
     foreach ($ids as $key => $listid) {
         if ($listid == JRequest::getInt('listid')) {
             $listModel = JModel::getInstance('List', 'FabrikFEModel');
             $listModel->setId(JRequest::getInt('listid'));
             $item = $listModel->getTable();
             $db = $listModel->getDbo();
             $query = $db->getQuery(true);
             $el = FabrikString::safeColName($approveEls[$key]);
             try {
                 $query->update($db->nameQuote($item->db_table_name))->set($el . ' = ' . $db->quote($v))->where($item->db_primary_key . ' = ' . $db->quote(JRequest::getVar('rowid')));
                 $db->setQuery($query);
                 $db->query();
             } catch (JException $e) {
                 JError::raiseError(500, $e->getMessage());
             }
         }
     }
 }
Exemplo n.º 28
0
 /**
  * return the javascript to create an instance of the class defined in formJavascriptClass
  * @param object parameters
  * @param object table model
  * @param array [0] => string table's form id to contain plugin
  * @return bool
  */
 function loadJavascriptInstance($params, $model, $args)
 {
     $form_id = $args[0];
     FabrikHelperHTML::script('element.js', 'media/com_fabrik/js/');
     $tableModel =& JModel::getInstance('table', 'FabrikModel');
     $tableModel->setId(JRequest::getVar('tableid'));
     $elements =& $tableModel->getElements('filtername');
     $pels = $params->get('inline_editable_elements');
     $use = trim($pels) == '' ? array() : explode(",", $pels);
     $els = array();
     foreach ($elements as $key => $val) {
         $key = FabrikString::safeColNameToArrayKey($key);
         if (empty($use) || in_array($key, $use)) {
             $els[$key] = new stdClass();
             $els[$key]->elid = $val->_id;
             $els[$key]->plugin = $val->getElement()->plugin;
             //load in all element js classes
             $val->formJavascriptClass();
         }
     }
     $opts = new stdClass();
     $opts->mooversion = FabrikWorker::getMooVersion() == 1 ? 1.2 : 1.1;
     $opts->elements = $els;
     $opts->tableid = $tableModel->_id;
     $opts->focusClass = 'focusClass';
     $opts->liveSite = COM_FABRIK_LIVESITE;
     $opts->editEvent = $params->get('inline_edit_event', 'dblclick');
     $opts->tabSave = $params->get('inline_tab_save', false);
     $opts->showCancel = $params->get('inline_show_cancel', true);
     $opts->showSave = $params->get('inline_show_save', true);
     $opts->loadFirst = (bool) $params->get('inline_load_first', false);
     $opts = json_encode($opts);
     $lang = $this->_getLang();
     $lang = json_encode($lang);
     $this->jsInstance = "new FbTableInlineEdit('{$form_id}', {$opts}, {$lang})";
     return true;
 }
Exemplo n.º 29
0
 function onCanEdit($params, $tableModel, $row)
 {
     // If $row is null, we were called from the table's canEdit() in a per-table rather than per-row context,
     // and we don't have an opinion on per-table edit permissions, so just return true.
     if (is_null($row) || is_null($row[0])) {
         return true;
     }
     if (is_array($row[0])) {
         $data = JArrayHelper::toObject($row[0]);
     } else {
         $data = $row[0];
     }
     //$field = str_replace('.', '___', $params->get('caneditrow_field'));
     $field = $params->get('caneditrow_field');
     $field = FabrikString::safeColnameToArrayKey($field);
     // $$$ rob if no can edit field selected in admin return true
     if (trim($field) == '') {
         return true;
     }
     // If they provided some PHP to eval, we ignore the other settings and just run their code
     $caneditrow_eval = $params->get('caneditrow_eval', '');
     if (!empty($caneditrow_eval)) {
         $w = new FabrikWorker();
         $data = JArrayHelper::fromObject($data);
         $caneditrow_eval = $w->parseMessageForPlaceHolder($caneditrow_eval, $data);
         $caneditrow_eval = @eval($caneditrow_eval);
         FabrikWorker::logEval($caneditrow_eval, 'Caught exception on eval in can edit row : %s');
         return $caneditrow_eval;
     } else {
         // No PHP given, so just do a simple match on the specified element and value settigns.
         if ($params->get('caneditrow_useraw', '0') == '1') {
             $field .= '_raw';
         }
         $value = $params->get('caneditrow_value');
         return $data->{$field} == $value;
     }
 }
Exemplo n.º 30
0
 /**
  * Get base tag url
  *
  * @param   string $fullName Full name (key value to remove from querystring)
  * @param   string $rootUrl  Optional root to use rather than REQUEST_URI
  *
  * @return string
  */
 public static function tagBaseUrl($fullName, $rootUrl = null)
 {
     $url = filter_var(ArrayHelper::getValue($_SERVER, 'REQUEST_URI', 'index.php'), FILTER_SANITIZE_URL);
     $bits = explode('?', $url);
     $root = isset($rootUrl) ? $rootUrl : FArrayHelper::getValue($bits, 0, '', 'string');
     $bits = FArrayHelper::getValue($bits, 1, '', 'string');
     $bits = explode("&", $bits);
     for ($b = count($bits) - 1; $b >= 0; $b--) {
         $parts = explode("=", $bits[$b]);
         if (count($parts) > 1) {
             $key = FabrikString::ltrimword(FabrikString::safeColNameToArrayKey($parts[0]), '&');
             if ($key == $fullName) {
                 unset($bits[$b]);
             }
             if ($key == $fullName . '[value]') {
                 unset($bits[$b]);
             }
             if ($key == $fullName . '[condition]') {
                 unset($bits[$b]);
             }
         }
     }
     $url = $root . '?' . implode('&', $bits);
     return $url;
 }