Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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());
             }
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Get the table filter for the element
  * @param bol do we render as a normal filter or as an advanced searc filter
  * if normal include the hidden fields as well (default true, use false for advanced filter rendering)
  * @return string filter html
  */
 function getFilter($counter = 0, $normal = true)
 {
     $table =& $this->getTableModel()->getTable();
     $elName = $this->getFullName(false, true, false);
     $htmlid = $this->getHTMLId() . 'value';
     $elName = FabrikString::safeColName($elName);
     $v = 'fabrik___filter[table_' . $table->id . '][value]';
     $v .= $normal ? '[' . $counter . ']' : '[]';
     $default = $this->getDefaultFilterVal($normal, $counter);
     $rows = $this->filterValueList($normal);
     $return = JHTML::_('select.genericlist', $rows, $v, 'class="inputbox fabrik_filter" size="1" ', 'value', 'text', $default, $htmlid);
     if ($normal) {
         $return .= $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return .= $this->getAdvancedFilterHiddenFields();
     }
     return $return;
 }
Ejemplo n.º 10
0
 /**
  * Build the sql query to filter the data
  *
  * @param   object  $params  plugin params
  *
  * @return  string  query's where statement
  */
 protected function getQuery($params)
 {
     $input = $this->app->input;
     $lookUps = $input->get('radius_lookup' . $this->renderOrder, array(), 'array');
     $lookUps = array_filter($lookUps, function ($v) {
         return (string) $v === '1';
     });
     $ids = array_keys($lookUps);
     $ids = ArrayHelper::toInteger($ids);
     $listModel = new FabrikFEModelList();
     $listModel->setId($params->get('radius_lookup_list'));
     $listModel->setLimits(0, -1);
     $key = $listModel->getPrimaryKey();
     $listModel->setPluginQueryWhere('list.radius_lookup', $key . ' IN (' . implode(',', $ids) . ')');
     $data = $listModel->getData();
     $distanceField = $params->get('distance_field') . '_raw';
     $data = $listModel->getData();
     list($latitude, $longitude) = $this->getSearchLatLon();
     if (trim($latitude) === '' && trim($longitude) === '') {
         $input->set('radius_search_active' . $this->renderOrder, array(0));
         return;
     }
     // Need to unset for multiple radius searches to work
     unset($this->mapElement);
     $el = $this->getMapElement();
     $el = FabrikString::safeColName($el->getFullName(false, false));
     // Crazy sql to get the lat/lon from google map element
     $latField = "SUBSTRING_INDEX(TRIM(LEADING '(' FROM {$el}), ',', 1)";
     $lonField = "SUBSTRING_INDEX(SUBSTRING_INDEX({$el}, ',', -1), ')', 1)";
     $query = array();
     $unit = $params->get('radius_lookup_unit', 'km');
     foreach ($data as $group) {
         foreach ($group as $row) {
             $v = $row->{$distanceField};
             if ($unit == 'km') {
                 $query[] = "((((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latField} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latField} *pi()/180)) * cos(((" . $longitude . "- {$lonField})*pi()/180))))*180/pi())*60*1.1515*1.609344) <= " . $v . ')';
             } else {
                 $query[] = "((((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latField} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latField} *pi()/180)) * cos(((" . $longitude . "- {$lonField})*pi()/180))))*180/pi())*60*1.1515) <= " . $v . ')';
             }
         }
     }
     $query = '(' . implode(' OR ', $query) . ')';
     return $query;
 }
Ejemplo n.º 11
0
	/**
	 * delete an event
	 */

	function deleteEvent()
	{
		$id = (int)JRequest::getVar('id');
		$listid = JRequest::getInt('listid');
		$listModel = JModel::getInstance('list', 'FabrikFEModel');
		$listModel->setId($listid);
		$list = $listModel->getTable();
		$tableDb = $listModel->getDb();
		$db = FabrikWorker::getDbo();
		$db->setQuery("SELECT db_table_name FROM #__{package}_lists WHERE id = $listid");
		$tablename = $db->loadResult();
		$tableDb->setQuery("DELETE FROM ".FabrikString::safeColName($tablename)." WHERE $list->db_primary_key = $id");
		$tableDb->query();
	}
Ejemplo n.º 12
0
    function getToField()
    {
        $this->_type = 'table';
        $this->_id = JRequest::getInt('id');
        $params =& $this->getParams();
        $renderOrder = JRequest::getInt('renderOrder');
        $toType = $params->get('emailtable_to_type');
        $toType = is_array($toType) ? JArrayHelper::getValue($toType, $renderOrder, 'list') : $toType;
        if ($toType == 'field') {
            $to = $params->get('emailtable_to');
            $to = is_array($to) ? JArrayHelper::getValue($to, $renderOrder) : $to;
            return "<input name=\"email_to\" id=\"email_to\" value=\"" . $to . "\" readonly=\"true\" />";
        } else {
            if ($toType == 'list') {
                return $this->formModel->getElementList('email_to');
            } else {
                if ($toType == 'table' || $toType == 'table_picklist') {
                    $emailtable_to_table_table = $params->get('emailtable_to_table_table');
                    if (is_array($emailtable_to_table_table)) {
                        $emailtable_to_table_table = $emailtable_to_table_table[$renderOrder];
                    }
                    $emailtable_to_table_email = $params->get('emailtable_to_table_email');
                    if (is_array($emailtable_to_table_email)) {
                        $emailtable_to_table_email = $emailtable_to_table_email[$renderOrder];
                    }
                    $emailtable_to_table_name = $params->get('emailtable_to_table_name');
                    if (is_array($emailtable_to_table_name)) {
                        $emailtable_to_table_name = $emailtable_to_table_name[$renderOrder];
                    }
                    if (empty($emailtable_to_table_name)) {
                        $emailtable_to_table_name = $emailtable_to_table_email;
                    }
                    $toTableModel =& JModel::getInstance('table', 'FabrikModel');
                    $toTableModel->setId($emailtable_to_table_table);
                    //$toFormModel =& $toTableModel->getFormModel();
                    $toDb = $toTableModel->getDb();
                    $emailtable_to_table_name = FabrikString::safeColName($emailtable_to_table_name);
                    $emailtable_to_table_email = FabrikString::safeColName($emailtable_to_table_email);
                    $emailtable_to_table = $toDb->nameQuote($toTableModel->getTable()->db_table_name);
                    $toDb->setQuery("SELECT {$emailtable_to_table_email} AS email, {$emailtable_to_table_name} AS name FROM {$emailtable_to_table} ORDER BY name ASC");
                    $results = $toDb->loadObjectList();
                    $empty = new stdClass();
                    if ($toType == 'table_picklist') {
                        // $$$ hugh - yeah yeah, I'll move these into assets when I get a spare minute or three.
                        $html = '
<style type="text/css">
	.fabrik_email_holder	{ width:200px; float:left; }
	#email_add,#email_remove	{ display:block; width:150px; text-align:center; border:1px solid #ccc; background:#eee; }
	.fabrik_email_holder select	{ margin:0 0 10px 0; width:150px; padding:5px; height:200px; }
</style>
<script type="text/javascript">
	window.addEvent(\'domready\', function() {
		$(\'email_add\').addEvent(\'click\', function() {
			$(\'email_to_selectfrom\').getSelected().each(function(el) {
				el.inject($(\'email_to\'));
			});
		});
		$(\'email_remove\').addEvent(\'click\', function() {
			$(\'email_to\').getSelected().each(function(el) {
				el.inject($(\'email_to_selectfrom\'));
			});
		});
	});
</script>
';
                        $html .= '<div class="fabrik_email_holder">';
                        $html .= JHTML::_('select.genericlist', $results, 'email_to_selectfrom[]', 'class="fabrikinput inputbox" multiple="multiple" size="5"', 'email', 'name', '', 'email_to_selectfrom');
                        $html .= '<a href="javascript:;" id="email_add">add &gt;&gt;</a>';
                        $html .= '</div>';
                        $html .= '<div class="fabrik_email_holder">';
                        $html .= JHTML::_('select.genericlist', $empty, 'email_to[]', 'class="fabrikinput inputbox" multiple="multiple" size="5"', 'email', 'name', '', 'email_to');
                        $html .= '<a href="javascript:;" id="email_remove">&lt;&lt; remove</a>';
                        $html .= '</div>';
                        $html .= '<div style="clear:both;"></div>';
                    } else {
                        $html = JHTML::_('select.genericlist', $results, 'email_to[]', 'class="fabrikinput inputbox" multiple="multiple" size="5"', 'email', 'name', '', 'email_to');
                    }
                    return $html;
                }
            }
        }
    }
Ejemplo n.º 13
0
 function dochown()
 {
     $app =& JFactory::getApplication();
     $tableModel =& $this->getModel('Table');
     $tableModel->setId(JRequest::getVar('id', 0));
     $db = $tableModel->getDb();
     $params =& $tableModel->getParams();
     $renderOrder = JRequest::getInt('renderOrder', 0);
     $recordids = explode(',', JRequest::getVar('recordids'));
     $lang =& JFactory::getLanguage();
     $lang->load('com_fabrik.plg.table.chown');
     $chown_to_val = JRequest::getInt('chown_to_val', 0);
     if (empty($chown_to_val)) {
         echo '<div class="chown_result">' . JText::_('PLG_TABLE_CHOWN_NO_SELECTION') . '</div>';
         return;
     }
     $chowns = array();
     $chown_field_to_change_1 = $params->get('chown_field_to_change_1');
     if (is_array($chown_field_to_change_1)) {
         $chown_field_to_change_1 = JArrayHelper::getValue($chown_field_to_change_1, $renderOrder, '');
     }
     if (!empty($chown_field_to_change_1)) {
         $chowns[] = "{$chown_field_to_change_1} = " . $db->Quote($chown_to_val);
     }
     $chown_field_to_change_2 = $params->get('chown_field_to_change_2');
     if (is_array($chown_field_to_change_2)) {
         $chown_field_to_change_2 = JArrayHelper::getValue($chown_field_to_change_2, $renderOrder, '');
     }
     if (!empty($chown_field_to_change_2)) {
         $chowns[] = "{$chown_field_to_change_2} = " . $db->Quote($chown_to_val);
     }
     $chown_field_to_change_3 = $params->get('chown_field_to_change_3');
     if (is_array($chown_field_to_change_3)) {
         $chown_field_to_change_3 = JArrayHelper::getValue($chown_field_to_change_3, $renderOrder, '');
     }
     if (!empty($chown_field_to_change_3)) {
         $chowns[] = "{$chown_field_to_change_3} = " . $db->Quote($chown_to_val);
     }
     if (empty($chowns)) {
         echo '<div class="chown_result">' . JText::_('PLG_TABLE_CHOWN_NO_SELECTION') . '</div>';
         return;
     }
     $table_name = $db->nameQuote($tableModel->getTable()->db_table_name);
     $pk_field = FabrikString::safeColName($tableModel->getTable()->db_primary_key);
     $query = "UPDATE {$table_name} SET " . implode(',', $chowns) . " WHERE {$pk_field} IN (" . implode(',', $recordids) . ")";
     $db->setQuery($query);
     if (!$db->query()) {
         echo '<div class="chown_result">' . JText::sprintf('PLG_TABLE_CHOWN_X_ERRORS', $db->getErrorMsg()) . '</div>';
     } else {
         echo '<div class="chown_result">' . JText::sprintf('PLG_TABLE_CHOWN_X_CHANGED', count($recordids)) . '</div>';
     }
     echo '<div class="chown_result"><button onclick="window.parent.location.reload()">OK</button></div>';
     /*
     $addmany_to_fk_val = JRequest::getInt('addmany_to_fk_val');
     $tableModel =& $this->getModel('Table');
     $tableModel->setId(JRequest::getVar('id', 0));
     //$formModel =& $tableModel->getForm();
     //$this->formModel =& $formModel;
     $params =& $tableModel->getParams();
     $addmany_to_table = $params->get('addmany_to_table');
     if (is_array($addmany_to_table)) {
     	$addmany_to_table = $addmany_to_table[$renderOrder];
     }
     $addmany_to_fk = $params->get('addmany_to_fk');
     if (is_array($addmany_to_fk)) {
     	$addmany_to_fk = $addmany_to_fk[$renderOrder];
     }
     $addmany_from_fk = $params->get('addmany_from_fk');
     if (is_array($addmany_from_fk)) {
     	$addmany_from_fk = $addmany_from_fk[$renderOrder];
     }
     
     $toTableModel =& $this->getModel( 'Table' );
     $toTableModel->setId($addmany_to_table);
     $toFormModel =& $toTableModel->getFormModel();
     
     $addmany_to_date = '';
     $date_elementModel =& $toFormModel->getElement('date_time');
     if (!empty($date_elementModel)) {
     	$addmany_to_date = FabrikString::safeColName($date_elementModel->getFullName(false, true, false));
     }
     
     $addmany_to_fk = FabrikString::safeColName($addmany_to_fk);
     $addmany_to_fk_short = FabrikString::shortColName($addmany_to_fk);
     $addmany_from_fk = FabrikString::safeColName($addmany_from_fk);
     $toDb = $toTableModel->getDb();
     $addmany_to_db_table_name = $toDb->nameQuote($toTableModel->getTable()->db_table_name);
     $addmany_from_db_table_name = $toDb->nameQuote($tableModel->getTable()->db_table_name);
     $addmany_to_fk_val = $toDb->Quote($addmany_to_fk_val);
     
     $addmany_added = 0;
     $addmany_already_exist = 0;
     $addmany_add_errors = 0;
     
     $addmany_additional_child_fields = $params->get('addmany_additional_child_fields', '');
     if (is_array($addmany_additional_child_fields)) {
     	$addmany_additional_child_fields = JArrayHelper::getValue($addmany_additional_child_fields, $renderOrder, '');
     }
     $addmany_additional_child_from_fields = array();
     $addmany_additional_child_to_fields = array();
     $addmany_additional_child_from_field_values = array();
     if (!empty($addmany_additional_child_fields)) {
     	$toJoinModel = $toFormModel->getElement($addmany_to_fk_short);
     	//$toJoinElement = $toJoinModel->getElement();
     	$toJoinParams = $toJoinModel->getParams();
     	$addmany_child_db_table_name = $toJoinParams->get('join_db_name', '');
     	$addmany_child_pk = $toJoinParams->get('join_key_column', '');
     	foreach (explode(';', $addmany_additional_child_fields) as $field_pairs) {
     		list($from_field,$to_field) = explode(',', $field_pairs);
     		$addmany_additional_child_from_fields[] = $from_field;
     		$addmany_additional_child_to_fields[] = $to_field;
     	}
     	$query = "SELECT " . implode(',', $addmany_additional_child_from_fields) . " FROM $addmany_child_db_table_name WHERE $addmany_child_pk = $addmany_to_fk_val";
     	$toDb->setQuery($query);
     	$addmany_additional_child_from_field_values = $toDb->loadObject();
     }
     
     $addmany_additional_parent_fields = $params->get('addmany_additional_parent_fields', '');
     if (is_array($addmany_additional_parent_fields)) {
     	$addmany_additional_parent_fields = JArrayHelper::getValue($addmany_additional_parent_fields, $renderOrder, '');
     }
     $addmany_additional_parent_from_fields = array();
     $addmany_additional_parent_to_fields = array();
     $addmany_additional_parent_from_field_values = array();
     if (!empty($addmany_additional_parent_fields)) {
     	$addmany_from_pk = $params->get('addmany_from_pk');
     	if (is_array($addmany_from_pk)) {
     		$addmany_from_pk = $addmany_from_pk[$renderOrder];
     	}
     	$addmany_from_pk = FabrikString::safeColName($addmany_from_pk);
     	$addmany_from_pk_short = FabrikString::shortColName($addmany_from_pk);
     	$fromDb = $tableModel->getDb();
     	foreach (explode(';', $addmany_additional_parent_fields) as $field_pairs) {
     		list($from_field,$to_field) = explode(',', $field_pairs);
     		$addmany_additional_parent_from_fields[] = $from_field;
     		$addmany_additional_parent_to_fields[] = $to_field;
     	}
     	$query = "SELECT $addmany_from_pk_short, " . implode(',', $addmany_additional_parent_from_fields) . " FROM $addmany_from_db_table_name WHERE $addmany_from_pk IN (" . implode(',', $recordids) . ")";
     	$fromDb->setQuery($query);
     	$addmany_additional_parent_from_field_values = $fromDb->loadObjectList($addmany_from_pk_short);
     }
     
     foreach ($recordids as $recordid) {
     	$addmany_from_fk_val = $toDb->Quote($recordid);
     	$query = "SELECT COUNT(*) FROM $addmany_to_db_table_name WHERE $addmany_to_fk = $addmany_to_fk_val AND $addmany_from_fk = $addmany_from_fk_val";
     	$toDb->setQuery($query);
     	$exists = (int)$toDb->loadResult();
     	if (empty($exists)) {
     		$field_values = array();
     		$field_names = array();
     		$field_names[] = $addmany_to_fk;
     		$field_values[] = $addmany_to_fk_val;
     		$field_names[] = $addmany_from_fk;
     		$field_values[] = $addmany_from_fk_val;
     		if (!empty($addmany_to_date)) {
     			$field_names[] = $addmany_to_date;
     			$field_values[] = "NOW()";
     		}
     		if (!empty($addmany_additional_parent_from_field_values)) {
     			if (array_key_exists($recordid, $addmany_additional_parent_from_field_values)) {
     				foreach($addmany_additional_parent_from_fields as $from_index => $from_field) {
     					$field_values[] = $toDb->Quote($addmany_additional_parent_from_field_values[$recordid]->$from_field);
     					$field_names[] = $addmany_additional_parent_to_fields[$from_index];
     				}
     			}
     		}
     		if (!empty($addmany_additional_child_from_field_values)) {
     				foreach($addmany_additional_child_from_fields as $from_index => $from_field) {
     					$field_values[] = $toDb->Quote($addmany_additional_child_from_field_values->$from_field);
     					$field_names[] = $addmany_additional_child_to_fields[$from_index];
     				}
     		}
     		$query = "INSERT INTO $addmany_to_db_table_name (" . implode(',', $field_names) . ") VALUES (" . implode(',', $field_values) . ")";
     		$toDb->setQuery($query);
     		if ($toDb->query() === false) {
     			$addmany_add_errors++;
     		}
     		else {
     			$addmany_added++;
     		}
     	}
     	else {
     		$addmany_already_exist++;
     	}
     }
     
     $lang =& JFactory::getLanguage();
     $lang->load('com_fabrik.plg.table.addmany');
     
     echo '<p>' . JText::sprintf('PLG_TABLE_ADDMANY_X_ADDED', $addmany_added) . '</p>';
     if ($addmany_already_exist > 0) {
     	echo '<p>' . JText::sprintf('PLG_TABLE_ADDMANY_X_EXISTED', $addmany_already_exist) . '</p>';
     }
     if ($addmany_add_errors > 0) {
     	echo '<p>' . JText::sprintf('PLG_TABLE_ADDMANY_X_ERRORS', $addmany_add_errors) . '</p>';
     }
     echo "<button onclick='alert(window.parent.location);window.parent.location.reload()'>OK</button>";
     */
 }
Ejemplo n.º 14
0
 /**
  * ajax method to get a json array of value/text pairs of options for the
  * auto-complete rendering of the element.
  */
 public function onAutocomplete_options()
 {
     //needed for ajax update (since we are calling this method via dispatcher element is not set
     $this->_id = JRequest::getInt('element_id');
     $this->getElement(true);
     $db =& FabrikWorker::getDbo();
     $c = $this->_getValColumn();
     if (!strstr($c, 'CONCAT')) {
         $c = FabrikString::safeColName($c);
     }
     $this->_autocomplete_where = $c . ' LIKE ' . $db->Quote('%' . JRequest::getVar('value') . '%');
     $tmp =& $this->_getOptions(array(), 0, false);
     echo json_encode($tmp);
 }
Ejemplo n.º 15
0
 /**
  * Get the first last, prev and next record ids
  *
  * @return  object
  */
 protected function getNavIds()
 {
     if (isset($this->navIds)) {
         return $this->navIds;
     }
     $formModel = $this->getModel();
     $listModel = $formModel->getListModel();
     $listModel->filters = null;
     $filterModel = $listModel->getFilterModel();
     $filterModel->destroyRequest();
     $this->app->input->set('view', 'list');
     $listref = $listModel->getId() . '_com_' . $this->package . '_' . $listModel->getId();
     $this->app->input->set('listref', $listref);
     $table = $listModel->getTable();
     $db = $listModel->getDb();
     $query = $db->getQuery(true);
     // As we are selecting on primary key we can select all rows - 3000 records load in 0.014 seconds
     $query->select($table->db_primary_key)->from($table->db_table_name);
     $query = $listModel->buildQueryJoin($query);
     $query = $listModel->buildQueryWhere(true, $query);
     $query = $listModel->buildQueryOrder($query);
     foreach ($listModel->orderEls as $orderName) {
         $orderName = FabrikString::safeColNameToArrayKey($orderName);
         $query->select(FabrikString::safeColName($orderName) . ' AS ' . $orderName);
     }
     $db->setQuery($query);
     $rows = $db->loadColumn();
     $keys = array_flip($rows);
     $o = new stdClass();
     $o->index = FArrayHelper::getValue($keys, $formModel->getRowId(), 0);
     $o->first = $rows[0];
     $o->lastKey = count($rows) - 1;
     $o->last = $rows[$o->lastKey];
     $o->next = $o->index + 1 > $o->lastKey ? $o->lastKey : $rows[$o->index + 1];
     $o->prev = $o->index - 1 < 0 ? 0 : $rows[$o->index - 1];
     $this->navIds = $o;
     $this->app->input->set('view', 'form');
     return $this->navIds;
 }
Ejemplo n.º 16
0
 /**
  * delete an event
  */
 public function deleteEvent()
 {
     $id = (int) JRequest::getVar('id');
     $listid = JRequest::getInt('listid');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     $listModel->setId($listid);
     $list = $listModel->getTable();
     $tableDb = $listModel->getDb();
     $db = FabrikWorker::getDbo(true);
     $query = $db->getQuery(true);
     $query->select('db_table_name')->from('#__{package}_lists')->where('id = ' . $listid);
     $db->setQuery($query);
     $tablename = $db->loadResult();
     $tableDb->setQuery("DELETE FROM " . FabrikString::safeColName($tablename) . " WHERE {$list->db_primary_key} = {$id}");
     $tableDb->query();
 }
Ejemplo n.º 17
0
 /**
  * Get the table filter for the element
  *
  * @param   int   $counter  Filter order
  * @param   bool  $normal   Do we render as a normal filter or as an advanced search filter
  * if normal include the hidden fields as well (default true, use false for advanced filter rendering)
  *
  * @return  string	Filter html
  */
 public function getFilter($counter = 0, $normal = true)
 {
     $listModel = $this->getlistModel();
     $elName = $this->getFullName(true, false);
     $elName = FabrikString::safeColName($elName);
     $v = 'fabrik___filter[list_' . $listModel->getRenderContext() . '][value]';
     $v .= $normal ? '[' . $counter . ']' : '[]';
     $default = $this->getDefaultFilterVal($normal, $counter);
     $rows = $this->filterValueList($normal);
     $this->getFilterDisplayValues($default, $rows);
     $return = array();
     $element = $this->getElement();
     if ($element->filter_type == 'hidden') {
         $return[] = $this->singleFilter($default, $v, 'hidden');
     } else {
         $return[] = $this->selectFilter($rows, $default, $v);
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName, false, $normal);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }
Ejemplo n.º 18
0
 /**
  * Set visualization prefilters
  *
  * @return  void
  */
 public function setPrefilters()
 {
     $listModels = $this->getListModels();
     $filters = array();
     $params = $this->getParams();
     $prefilters = (array) $params->get('prefilters');
     $c = 0;
     foreach ($listModels as $listModel) {
         // Set prefilter params
         $listParams = $listModel->getParams();
         $prefilter = FArrayHelper::getValue($prefilters, $c);
         $prefilter = JArrayHelper::fromObject(json_decode($prefilter));
         $conditions = (array) $prefilter['filter-conditions'];
         if (!empty($conditions)) {
             $fields = $prefilter['filter-fields'];
             foreach ($fields as &$f) {
                 $f = FabrikString::safeColName($f);
             }
             $listParams->set('filter-fields', $fields);
             $listParams->set('filter-conditions', $prefilter['filter-conditions']);
             $listParams->set('filter-value', $prefilter['filter-value']);
             $listParams->set('filter-access', $prefilter['filter-access']);
             $listParams->set('filter-eval', $prefilter['filter-eval']);
         }
         $c++;
     }
 }
Ejemplo n.º 19
0
 function getChart()
 {
     $params = $this->getParams();
     $this->calc_prefixmap = array('sum___' => 'sums', 'avg___' => 'avgs', 'med___' => 'medians', 'cnt___' => 'count');
     $w = (int) $params->get('chart_width', 200);
     $h = (int) $params->get('chart_height', 200);
     $graph = $params->get('graph_type');
     $fillGraphs = $params->get('fill_line_graph');
     $x_axis_label = (array) $params->get('x_axis_label');
     $chartElements = (array) $params->get('chart_elementList');
     $legends = $params->get('graph_show_legend', '');
     $chxl_override = $params->get('chart_chxl', '');
     $chxl_override = trim(str_replace(',', '|', $chxl_override), ',');
     $chds_override = $params->get('chart_chds', '');
     $chds_override = trim(str_replace('|', ',', $chds_override), '|');
     $chg_override = $params->get('chart_chg', '');
     $chm_override = $params->get('chart_chm', '');
     $chma_override = $params->get('chart_chma', '');
     $c = 0;
     $gdata = array();
     $glabels = array();
     $max = 0;
     $min = 0;
     //$calculationLabels = array();
     $calculationData = array();
     $tableDatas = $this->getTableData();
     foreach ($tableDatas as $tableData) {
         $alldata = $tableData['data'];
         $cals = $tableData['cals'];
         $column = $chartElements[$c];
         $listModel = $tableData['model'];
         //$measurement_unit = JArrayHelper::getValue($measurement_units, $c, '');
         $pref = substr($column, 0, 6);
         $label = JArrayHelper::getValue($x_axis_label, $c, '');
         $tmpgdata = array();
         $calcfound = $this->getCalcFound();
         if ($calcfound) {
             $column = substr($column, 6);
         }
         $elements = $listModel->getElements('filtername');
         $safename = FabrikString::safeColName($column);
         $colElement = $elements[$safename];
         if ($calcfound) {
             $calckey = $this->calc_prefixmap[$pref];
             // you shouldnt mix calculation elements with normal elements when creating the chart
             // so if ONE calculation element is found we use the calculation data rather than normal element data
             // this is because a calculation element only generates one value, if want to compare two averages then
             //they get rendered as two groups of data and on bar charts this overlays one average over the other, rather than next to it
             //$calcfound = true;
             $caldata = $cals[$calckey][$column . '_obj'];
             if (is_array($caldata)) {
                 foreach ($caldata as $k => $o) {
                     $calculationData[] = $colElement->getCalculationValue($o->value);
                 }
             }
             $gdata[$c] = implode(',', $tmpgdata);
             // $$$ hugh - playing around with pie charts
             $gsums[$c] = array_sum($calculationData);
         } else {
             $origColumn = $column;
             $column = $column . "_raw";
             //_raw fields are most likely to contain the value
             foreach ($alldata as $group) {
                 foreach ($group as $row) {
                     if (!array_key_exists($column, $row)) {
                         //didnt find a _raw column - revent to orig
                         $column = $origColumn;
                         if (!array_key_exists($column, $row)) {
                             JError::raiseWarning(E_NOTICE, $column . ': NOT FOUND - PLEASE CHECK IT IS PUBLISHED');
                             continue;
                         }
                     }
                     if (trim($row->{$column}) == '') {
                         $tmpgdata[] = -1;
                     } else {
                         $tmpgdata[] = $colElement->getCalculationValue($row->{$column});
                     }
                 }
                 $gdata[$c] = implode(',', $tmpgdata);
                 // $$$ hugh - playing around with pie charts
                 $gsums[$c] = array_sum($tmpgdata);
             }
         }
         $c++;
     }
     if ($calcfound) {
         $gdata = array(implode(',', $calculationData));
     }
     // $$$ hugh - pie chart data has to be summed - the API only takes a
     // single dataset for pie charts.  And it doesn't make sense trying to
     // chart individual row data for multiple elements in a pie chart.
     switch ($graph) {
         case 'p':
         case 'p3':
             list($chd, $chxl, $chds, $fillGraphs) = $this->pieChart($c, $gdata, $gsums);
             break;
         case 'bhs':
             list($chd, $chxl, $chds) = $this->horizontalBarChart($c, $gdata, $gsums);
             break;
         default:
             list($chd, $chxl, $chds) = $this->defaultChart($c, $gdata, $gsums);
             break;
     }
     list($colours, $fills) = $this->getColours();
     $return = '<img src="' . $this->_url . '?';
     $qs = 'chs=' . $w . 'x' . $h;
     $qs .= '&amp;chd=t:' . $chd;
     $qs .= '&amp;cht=' . $graph;
     $qs .= '&amp;chco=' . $colours;
     $qs .= '&amp;chxt=x,y';
     $qs .= '&amp;chxl=' . $chxl;
     $qs .= '&amp;chds=' . $chds;
     if (!empty($chm_override)) {
         $qs .= '&amp;chm=' . $chm_override;
     }
     if (!empty($chma_override)) {
         $qs .= '&amp;chma=' . $chma_override;
     } else {
         if ($fillGraphs) {
             $qs .= '&amp;chm=' . implode('|', $fills);
         }
     }
     if ($legends) {
         $qs .= '&amp;chdl=' . implode('|', $this->getAxisLabels($c));
     }
     if (!empty($chg_override)) {
         $qs .= '&amp;chg=' . $chg_override;
     } else {
         if ($fillGraphs) {
             $qs .= '&amp;chm=' . implode('|', $fills);
         }
     }
     $qs .= '&amp;' . $params->get('chart_custom');
     $return .= $qs . '" alt="' . $this->_row->label . '" />';
     $this->image = $return;
     return $return;
 }
Ejemplo n.º 20
0
 /**
  * Get the list filter for the element
  * Note: uses FabDate as if date element first to be found in advanced search, and advanced search run on another
  * element the list model in getAdvancedSearchElementList() builds the first filter (this element) with the data
  * from the first search which was throwing '"500 - DateTime::__construct() ' errors
  *
  * see: http://fabrikar.com/forums/showthread.php?t=28231
  *
  * @param   int  $counter Filter order
  * @param   bool $normal  Do we render as a normal filter or as an advanced search filter
  *                        if normal include the hidden fields as well (default true, use false for advanced filter
  *                        rendering)
  *
  * @return  string    filter html
  */
 public function getFilter($counter = 0, $normal = true)
 {
     $listModel = $this->getListModel();
     $table = $listModel->getTable();
     $element = $this->getElement();
     $origTable = $table->db_table_name;
     $elName = $this->getFullName(true, false);
     $v = $this->filterName($counter, $normal);
     // Correct default got
     $default = $this->getDefaultFilterVal($normal, $counter);
     $this->filterDisplayValues = (array) $default;
     // $$$ hugh - in advanced search, _aJoins wasn't getting set
     $joins = $listModel->getJoins();
     foreach ($joins as $aJoin) {
         // Not sure why the group id key wasn't found - but put here to remove error
         if (array_key_exists('group_id', $aJoin)) {
             if ($aJoin->group_id == $element->group_id && $aJoin->element_id == 0) {
                 $fromTable = $aJoin->table_join;
                 $elName = str_replace($origTable . '.', $fromTable . '.', $elName);
             }
         }
     }
     $where = $listModel->buildQueryPrefilterWhere($this);
     $elName = FabrikString::safeColName($elName);
     $requestName = $elName . '___filter';
     if (array_key_exists($elName, $_REQUEST)) {
         if (is_array($_REQUEST[$elName]) && array_key_exists('value', $_REQUEST[$elName])) {
             $_REQUEST[$requestName] = $_REQUEST[$elName]['value'];
         }
     }
     $fType = $this->getFilterType();
     if (in_array($fType, array('dropdown', 'checkbox', 'multiselect'))) {
         $rows = $this->filterValueList($normal);
         $this->getFilterDisplayValues($default, $rows);
     }
     $return = array();
     switch ($fType) {
         case 'checkbox':
             $return[] = $this->checkboxFilter($rows, $default, $v);
             break;
         case 'range':
         case 'range-hidden':
             $return[] = $this->rangeFilter($default, $v);
             break;
         case 'dropdown':
         case 'multiselect':
             $return[] = $this->selectListFilter($rows, $default, $v);
             break;
         default:
         case 'field':
             $return[] = $this->singleFilter($default, $v);
             break;
         case 'hidden':
             $return[] = $this->hiddenFilter($default, $v);
             break;
         case 'auto-complete':
             $return[] = $this->autoCompleteFilter($default, $v);
             break;
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName, false, $normal);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }
Ejemplo n.º 21
0
 protected function getAvgQuery(&$tableModel, $label = "'calc'")
 {
     $params = $this->getParams();
     $format = $params->get('text_format', 'text');
     $decimal_places = $format == 'decimal' ? $params->get('decimal_length', '0') : '0';
     $table =& $tableModel->getTable();
     $joinSQL = $tableModel->_buildQueryJoin();
     $whereSQL = $tableModel->_buildQueryWhere();
     $name = $this->getFullName(false, false, false);
     $groupModel =& $this->getGroup();
     if ($groupModel->isJoin()) {
         //element is in a joined column - lets presume the user wants to sum all cols, rather than reducing down to the main cols totals
         return "SELECT ROUND(AVG({$name}), {$decimal_places}) AS value, {$label} AS label FROM " . FabrikString::safeColName($table->db_table_name) . " {$joinSQL} {$whereSQL}";
     } else {
         // need to do first query to get distinct records as if we are doing left joins the sum is too large
         return "SELECT ROUND(AVG(value), {$decimal_places}) AS value, label\r\nFROM (SELECT DISTINCT {$table->db_primary_key}, {$name} AS value, {$label} AS label FROM " . FabrikString::safeColName($table->db_table_name) . " {$joinSQL} {$whereSQL}) AS t";
     }
 }
Ejemplo n.º 22
0
 /**
  * used for the name of the filter fields
  * Over written here as we need to get the label field for field searches
  *
  * @return string element filter name
  */
 function getFilterFullName()
 {
     $elName = $this->getFullName(false, true, false);
     return FabrikString::safeColName($elName);
 }
Ejemplo n.º 23
0
 /**
  * Build the query for the avg calculation
  *
  * @param   model  &$listModel  list model
  * @param   array  $labels      Labels
  *
  * @return  string	sql statement
  */
 protected function getAvgQuery(&$listModel, $labels = array())
 {
     $label = count($labels) == 0 ? "'calc' AS label" : 'CONCAT(' . implode(', " & " , ', $labels) . ')  AS label';
     $item = $listModel->getTable();
     $joinSQL = $listModel->_buildQueryJoin();
     $whereSQL = $listModel->_buildQueryWhere();
     $name = $this->getFullName(false, false, false);
     $groupModel = $this->getGroup();
     $roundTo = (int) $this->getParams()->get('avg_round');
     $valueSelect = 'substr(' . $name . ' FROM 1 FOR 2) * 60 * 60 + substr(' . $name . ' FROM 4 FOR 2) * 60 + substr(' . $name . ' FROM 7 FOR 2)';
     // Element is in a joined column - lets presume the user wants to sum all cols, rather than reducing down to the main cols totals
     return "SELECT ROUND(AVG({$valueSelect}), {$roundTo}) AS value, {$label} FROM " . FabrikString::safeColName($item->db_table_name) . " {$joinSQL} {$whereSQL}";
 }
Ejemplo n.º 24
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
  *
  * @param   object  $params      plugin params
  * @param   object  &$formModel  form model
  *
  * @return	bool
  */
 public function onAfterProcess($params, &$formModel)
 {
     $app = JFactory::getApplication();
     $data = $formModel->_fullFormData;
     $this->data = $data;
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables');
     $log = FabTable::getInstance('log', 'FabrikTable');
     if (!$this->shouldProcess('paypal_conditon', $data, $formModel)) {
         return true;
     }
     $this->formModel = $formModel;
     $emailData = $this->getEmailData();
     $w = new FabrikWorker();
     $user = JFactory::getUser();
     $userid = $user->get('id');
     $ipn = $this->getIPNHandler($params);
     if ($ipn !== false) {
         if (method_exists($ipn, 'createInvoice')) {
             $ipn->createInvoice();
         }
     }
     $paypal_testmode = $params->get('paypal_testmode', false);
     $url = $paypal_testmode == 1 ? 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?' : 'https://www.paypal.com/cgi-bin/webscr?';
     $opts = array();
     $opts['cmd'] = $params->get('paypal_cmd', "_xclick");
     $email = $params->get('paypal_accountemail');
     if (trim($email) == '') {
         $email = $emailData[FabrikString::safeColNameToArrayKey($params->get('paypal_accountemail_element'))];
         if (is_array($email)) {
             $email = array_shift($email);
         }
     }
     $opts['business'] = "{$email}";
     $amount = $params->get('paypal_cost');
     $amount = $w->parseMessageForPlaceHolder($amount, $data);
     // @TODO Hugh/Rob check $$$tom: Adding eval option on cost field
     // Useful if you use a cart system which will calculate on total shipping or tax fee and apply it. You can return it in the Cost field.
     if ($params->get('paypal_cost_eval', 0) == 1) {
         $amount = @eval($amount);
     }
     if (trim($amount) == '') {
         $amount = JArrayHelper::getValue($emailData, FabrikString::safeColNameToArrayKey($params->get('paypal_cost_element')));
         if (is_array($amount)) {
             $amount = array_shift($amount);
         }
     }
     $opts['amount'] = "{$amount}";
     // $$$tom added Shipping Cost params
     $shipping_amount = $params->get('paypal_shipping_cost');
     if ($params->get('paypal_shipping_cost_eval', 0) == 1) {
         $shipping_amount = @eval($shipping_amount);
     }
     if (trim($shipping_amount) == '') {
         $shipping_amount = JArrayHelper::getValue($emailData, FabrikString::safeColNameToArrayKey($params->get('paypal_shipping_cost_element')));
         if (is_array($shipping_amount)) {
             $shipping_amount = array_shift($shipping_amount);
         }
     }
     $opts['shipping'] = "{$shipping_amount}";
     $item = $params->get('paypal_item');
     $item = $w->parseMessageForPlaceHolder($item, $emailData);
     if ($params->get('paypal_item_eval', 0) == 1) {
         $item = @eval($item);
         $item_raw = $item;
     }
     if (trim($item) == '') {
         $item_raw = JArrayHelper::getValue($emailData, FabrikString::safeColNameToArrayKey($params->get('paypal_item_element') . '_raw'));
         $item = $emailData[FabrikString::safeColNameToArrayKey($params->get('paypal_item_element'))];
         if (is_array($item)) {
             $item = array_shift($item);
         }
     }
     // $$$ hugh - strip any HTML tags from the item name, as PayPal doesn't like them.
     $opts['item_name'] = strip_tags($item);
     // $$$ rob add in subscription variables
     if ($opts['cmd'] === '_xclick-subscriptions') {
         $subTable = JModel::getInstance('List', 'FabrikFEModel');
         $subTable->setId((int) $params->get('paypal_subs_table'));
         $idEl = FabrikString::safeColName($params->get('paypal_subs_id', ''));
         $durationEl = FabrikString::safeColName($params->get('paypal_subs_duration', ''));
         $durationPerEl = FabrikString::safeColName($params->get('paypal_subs_duration_period', ''));
         $name = $params->get('paypal_subs_name', '');
         $subDb = $subTable->getDb();
         $query = $subDb->getQuery(true);
         $query->select('*, ' . $durationEl . ' AS p3, ' . $durationPerEl . ' AS t3, ' . $subDb->quote($item_raw) . ' AS item_number')->from($subTable->getTable()->db_table_name)->where($idEl . ' = ' . $subDb->quote($item_raw));
         $subDb->setQuery($query);
         $sub = $subDb->loadObject();
         if (is_object($sub)) {
             $opts['p3'] = $sub->p3;
             $opts['t3'] = $sub->t3;
             $opts['a3'] = $amount;
             $opts['no_note'] = 1;
             $opts['custom'] = '';
             $tmp = array_merge(JRequest::get('data'), JArrayHelper::fromObject($sub));
             // 'http://fabrikar.com/ '.$sub->item_name.' - User: subtest26012010 (subtest26012010)';
             $opts['item_name'] = $w->parseMessageForPlaceHolder($name, $tmp);
             $opts['invoice'] = $w->parseMessageForPlaceHolder($params->get('paypal_subs_invoice'), $tmp, false);
             if ($opts['invoice'] == '') {
                 $opts['invoice'] = uniqid('', true);
             }
             $opts['src'] = $w->parseMessageForPlaceHolder($params->get('paypal_subs_recurring'), $tmp);
             $amount = $opts['amount'];
             unset($opts['amount']);
         } else {
             JError::raiseError(500, 'Could not determine subscription period, please check your settings');
         }
     }
     /* $$$ rob 03/02/2011
      * check if we have a gateway subscription switch set up. This is for sites where
      * you can toggle between a subscription or a single payment. E.g. fabrikar com
      * if 'paypal_subscription_switch' is blank then use the $opts['cmd'] setting
      * if not empty it should be some eval'd PHP which needs to return true for the payment
      * to be treated as a subscription
      * We want to do this so that single payments can make use of Paypals option to pay via credit card
      * without a paypal account (subscriptions require a Paypal account)
      * We do this after the subscription code has been run as this code is still needed to look up the correct item_name
      */
     $subSwitch = $params->get('paypal_subscription_switch');
     if (trim($subSwitch) !== '') {
         $subSwitch = $w->parseMessageForPlaceHolder($subSwitch);
         $isSub = @eval($subSwitch);
         if (!$isSub) {
             // Reset the amount which was unset during subscription code
             $opts['amount'] = $amount;
             $opts['cmd'] = '_xclick';
             // Unset any subscription options we may have set
             unset($opts['p3']);
             unset($opts['t3']);
             unset($opts['a3']);
             unset($opts['no_note']);
         }
     }
     /* @TODO Hugh/Rob check $$$tom: Adding shipping options
      * Currently the admin select a user element on the form to compare it to the user id on the custom user table
      * Should we just make it to get the current user ID and use that?
      * $shipping_userid = $data[FabrikString::safeColNameToArrayKey($params->get('paypal_shipping_userelement') )];
      * if (is_array($shipping_userid)) {
      *	$shipping_userid = array_shift($shipping_userid);
      *}
      */
     $shipping_userid = $userid;
     if ($shipping_userid > 0) {
         $shipping_select = array();
         $db = FabrikWorker::getDbo();
         // $$$tom Surely there's a better Fabrik way of getting the table name...
         $query = $db->getQuery(true);
         $query->select('db_table_name')->from('#__{package}_lists')->where('id = ' . (int) $params->get('paypal_shippingdata_table'));
         $db->setQuery($query);
         $shipping_table = $db->loadResult();
         if ($params->get('paypal_shippingdata_firstname')) {
             $shipping_first_name = FabrikString::shortColName($params->get('paypal_shippingdata_firstname'));
             $shipping_select['first_name'] = $shipping_first_name;
         }
         if ($params->get('paypal_shippingdata_lastname')) {
             $shipping_last_name = FabrikString::shortColName($params->get('paypal_shippingdata_lastname'));
             $shipping_select['last_name'] = $shipping_last_name;
         }
         if ($params->get('paypal_shippingdata_address1')) {
             $shipping_address1 = FabrikString::shortColName($params->get('paypal_shippingdata_address1'));
             $shipping_select['address1'] = $shipping_address1;
         }
         if ($params->get('paypal_shippingdata_address2')) {
             $shipping_address2 = FabrikString::shortColName($params->get('paypal_shippingdata_address2'));
             $shipping_select['address2'] = $shipping_address2;
         }
         if ($params->get('paypal_shippingdata_zip')) {
             $shipping_zip = FabrikString::shortColName($params->get('paypal_shippingdata_zip'));
             $shipping_select['zip'] = $shipping_zip;
         }
         if ($params->get('paypal_shippingdata_state')) {
             $shipping_state = FabrikString::shortColName($params->get('paypal_shippingdata_state'));
             $shipping_select['state'] = $shipping_state;
         }
         if ($params->get('paypal_shippingdata_city')) {
             $shipping_city = FabrikString::shortColName($params->get('paypal_shippingdata_city'));
             $shipping_select['city'] = $shipping_city;
         }
         if ($params->get('paypal_shippingdata_country')) {
             $shipping_country = FabrikString::shortColName($params->get('paypal_shippingdata_country'));
             $shipping_select['country'] = $shipping_country;
         }
         $query->clear();
         $query->select($shipping_select)->from($shipping_table)->where(FabrikString::shortColName($params->get('paypal_shippingdata_id')) . ' = ' . $db->quote($shipping_userid));
         $db->setQuery($query);
         $user_shippingdata = $db->loadObject();
         foreach ($shipping_select as $opt => $val) {
             // $$$tom Since we test on the current userid, it always adds the &name=&street=....
             // Even if those vars are empty...
             if ($val) {
                 $opts[$opt] = $user_shippingdata->{$val};
             }
         }
     }
     if ($params->get('paypal_shipping_address_override', 0)) {
         $opts['address_override'] = 1;
     }
     $paypal_currency_code = $params->get('paypal_currencycode', 'USD');
     $paypal_currency_code = $w->parseMessageForPlaceHolder($paypal_currency_code, $data);
     $opts['currency_code'] = $paypal_currency_code;
     $paypal_test_site = $params->get('paypal_test_site', '');
     $paypal_test_site = rtrim($paypal_test_site, '/');
     if ($paypal_testmode == 1 && !empty($paypal_test_site)) {
         $ppurl = $paypal_test_site . '/index.php?option=com_fabrik&c=plugin&task=plugin.pluginAjax&formid=' . $formModel->get('id') . '&g=form&plugin=paypal&method=ipn';
     } else {
         $ppurl = COM_FABRIK_LIVESITE . '/index.php?option=com_fabrik&c=plugin&task=plugin.pluginAjax&formid=' . $formModel->get('id') . '&g=form&plugin=paypal&method=ipn';
     }
     $paypal_test_site_qs = $params->get('paypal_test_site_qs', '');
     if ($paypal_testmode == 1 && !empty($paypal_test_site_qs)) {
         $ppurl .= $paypal_test_site_qs;
     }
     $ppurl .= '&renderOrder=' . $this->renderOrder;
     $ppurl = urlencode($ppurl);
     $opts['notify_url'] = "{$ppurl}";
     $paypal_return_url = $params->get('paypal_return_url', '');
     $paypal_return_url = $w->parseMessageForPlaceHolder($paypal_return_url, $data);
     if ($paypal_testmode == 1 && !empty($paypal_return_url)) {
         if (preg_match('#^http:\\/\\/#', $paypal_return_url)) {
             $opts['return'] = $paypal_return_url;
         } else {
             if (!empty($paypal_test_site)) {
                 $opts['return'] = $paypal_test_site . '/' . $paypal_return_url;
             } else {
                 $opts['return'] = COM_FABRIK_LIVESITE . '/' . $paypal_return_url;
             }
         }
         if (!empty($paypal_test_site_qs)) {
             $opts['return'] .= $paypal_test_site_qs;
         }
     } elseif (!empty($paypal_return_url)) {
         if (preg_match('#^http:\\/\\/#', $paypal_return_url)) {
             $opts['return'] = $paypal_return_url;
         } else {
             $opts['return'] = COM_FABRIK_LIVESITE . '/' . $paypal_return_url;
         }
     } else {
         // Using default thanks() method so don't forget to add renderOrder
         if ($paypal_testmode == '1' && !empty($paypal_test_site)) {
             $opts['return'] = $paypal_test_site . '/index.php?option=com_fabrik&task=plugin.pluginAjax&formid=' . $formModel->get('id') . '&g=form&plugin=paypal&method=thanks&rowid=' . $data['rowid'] . '&renderOrder=' . $this->renderOrder;
         } else {
             $opts['return'] = COM_FABRIK_LIVESITE . '/index.php?option=com_fabrik&task=plugin.pluginAjax&formid=' . $formModel->get('id') . '&g=form&plugin=paypal&method=thanks&rowid=' . $data['rowid'] . '&renderOrder=' . $this->renderOrder;
         }
     }
     $opts['return'] = urlencode($opts['return']);
     $ipn_value = $params->get('paypal_ipn_value', '');
     $ipn_value = $w->parseMessageForPlaceHolder($ipn_value, $data);
     // Extra :'s will break parsing during IPN notify phase
     $ipn_value = str_replace(':', ';', $ipn_value);
     // $$$ hugh - thinking about putting in a call to a generic method in custom script
     // here and passing it a reference to $opts.
     if ($ipn !== false) {
         if (method_exists($ipn, 'checkOpts')) {
             if ($ipn->checkOpts($opts, $formModel) === false) {
                 // Log the info
                 $log->message_type = 'fabrik.paypal.onAfterProcess';
                 $msg = new stdClass();
                 $msg->opt = $opts;
                 $msg->data = $data;
                 $msg->msg = "Submission cancelled by checkOpts!";
                 $log->message = json_encode($msg);
                 $log->store();
                 return true;
             }
         }
     }
     $opts['custom'] = $data['formid'] . ':' . $data['rowid'] . ':' . $ipn_value;
     $qs = array();
     foreach ($opts as $k => $v) {
         $qs[] = "{$k}={$v}";
     }
     $url .= implode('&', $qs);
     /* $$$ rob 04/02/2011 no longer doing redirect from ANY plugin EXCEPT the redirect plugin
      * - instead a session var is set (com_fabrik.form.X.redirect.url)
      * as the preferred redirect url
      */
     $session = JFactory::getSession();
     $context = $formModel->getRedirectContext();
     /* $$$ hugh - fixing issue with new redirect, which now needs to be an array.
      * Not sure if we need to preserve existing session data, or just create a new surl array,
      * to force ONLY recirect to PayPal?
      */
     $surl = (array) $session->get($context . 'url', array());
     $surl[$this->renderOrder] = $url;
     $session->set($context . 'url', $surl);
     $session->set($context . 'redirect_content_how', 'samepage');
     // Log the info
     $log->message_type = 'fabrik.paypal.onAfterProcess';
     $msg = new stdClass();
     $msg->opt = $opts;
     $msg->data = $data;
     $log->message = json_encode($msg);
     $log->store();
     return true;
 }
Ejemplo n.º 25
0
 /**
  * Get the table filter for the element
  * @param bol do we render as a normal filter or as an advanced searc filter
  * if normal include the hidden fields as well (default true, use false for advanced filter rendering)
  * @return string filter html
  */
 function getFilter($counter = 0, $normal = true)
 {
     $listModel = $this->getlistModel();
     $table = $listModel->getTable();
     $elName = $this->getFullName(false, true, false);
     $htmlid = $this->getHTMLId() . 'value';
     $elName = FabrikString::safeColName($elName);
     $v = 'fabrik___filter[list_' . $listModel->getRenderContext() . '][value]';
     $v .= $normal ? '[' . $counter . ']' : '[]';
     $default = $this->getDefaultFilterVal($normal, $counter);
     $rows = $this->filterValueList($normal);
     $return = array();
     $element = $this->getElement();
     if ($element->filter_type == 'hidden') {
         $return[] = '<input type="text" name="' . $v . '" class="inputbox fabrik_filter" value="' . $default . '" id="' . $htmlid . '" />';
     } else {
         $return[] = JHTML::_('select.genericlist', $rows, $v, 'class="inputbox fabrik_filter" size="1" ', 'value', 'text', $default, $htmlid);
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }
Ejemplo n.º 26
0
 /**
  *
  * build the sql query to filter the data
  * @param object $params
  * return string query's where statement
  */
 protected function getQuery($params)
 {
     $app = JFactory::getApplication();
     $baseContext = $this->getSessionContext();
     $values = JArrayHelper::getValue($filters, 'value', array());
     $type = JRequest::getVar('radius_search_type');
     if ($type[0] == 'place') {
         $place = $app->getUserStateFromRequest($baseContext . 'radius_search_place', 'radius_search_place');
         list($latitude, $longitude) = $this->placeCoordinates($place);
     } else {
         $latitude = $app->getUserStateFromRequest($baseContext . 'lat', 'radius_search_lat');
         $longitude = $app->getUserStateFromRequest($baseContext . 'lon', 'radius_search_lon');
     }
     if (trim($latitude) === '' && trim($longitude) === '') {
         JRequest::setVar('radius_search_active', array(0));
         return;
     }
     $el =& $this->getMapElement();
     $el = FabrikString::safeColName($el->getFullName(false, false, false));
     //crazy sql to get the lat/lon from google map element
     $latfield = "SUBSTRING_INDEX(TRIM(LEADING '(' FROM {$el}), ',', 1)";
     $lonfield = "SUBSTRING_INDEX(SUBSTRING_INDEX({$el}, ',', -1), ')', 1)";
     $v = $this->getValue();
     if ($params->get('radius_unit', 'km') == 'km') {
         $query = "(((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latfield} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latfield} *pi()/180)) * cos(((" . $longitude . "- {$lonfield})*pi()/180))))*180/pi())*60*1.1515*1.609344) <= " . $v;
     } else {
         $query = "(((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latfield} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latfield} *pi()/180)) * cos(((" . $longitude . "- {$lonfield})*pi()/180))))*180/pi())*60*1.1515) <= " . $v;
     }
     return $query;
 }
Ejemplo n.º 27
0
 /**
  * build a polygon line to join up the markers
  * @return array of lines each line being an array of points
  */
 function getPolyline()
 {
     $params = $this->getParams();
     $lines = array();
     $polyelements = (array) $params->get('fb_gm_polyline_element');
     $listModels = $this->getlistModels();
     $c = 0;
     foreach ($listModels as $listModel) {
         $k = FabrikString::safeColName(FabrikString::rtrimword($polyelements[$c], '[]'));
         if ($k == '``') {
             $c++;
             continue;
         }
         $mapsElements = $listModel->getElementsOfType('googlemap');
         if (empty($mapsElements)) {
             JError::raiseError(500, JText::_('No google map element present in this list'));
             continue;
         }
         $coordColumn = $mapsElements[0]->getFullName(false, false, false);
         $table = $listModel->getTable();
         $where = $listModel->_buildQueryWhere();
         $join = $listModel->_buildQueryJoin();
         $db = $listModel->getDb();
         $db->setQuery("SELECT {$coordColumn} AS coords FROM {$table->db_table_name} {$join} {$where} ORDER BY {$k}");
         $data = $db->loadObjectList();
         $points = array();
         if (is_null($data)) {
             JError::raiseNotice(500, $db->getErrorMsg());
         } else {
             foreach ($data as $d) {
                 $d = $this->getCordsFromData($d->coords);
                 if ($d == array(0, 0)) {
                     continue;
                     //dont show icons with no data
                 }
                 $points[] = $d;
             }
         }
         $lines[] = $points;
         $c++;
     }
     return $lines;
 }
Ejemplo n.º 28
0
 /**
  * Build the sums() sql statement
  *
  * @return string
  */
 private function sums()
 {
     $params = $this->getParams();
     $sums = explode(',', $params->get('pivot_sum'));
     $db = $this->model->getDb();
     $fn = (int) $params->get('pivot_count', '0') == 1 ? 'COUNT' : 'SUM';
     foreach ($sums as &$sum) {
         $sum = trim($sum);
         $sum = FabrikString::rtrimword($sum, '_raw');
         $as = FabrikString::safeColNameToArrayKey($sum);
         $statement = $fn . '(' . FabrikString::safeColName($sum) . ')';
         $statement .= ' AS ' . $db->quoteName($as);
         $statement .= ', ' . $fn . '(' . FabrikString::safeColName($sum) . ')';
         $statement .= ' AS ' . $db->quoteName($as . '_raw');
         $sum = $statement;
     }
     $sum = implode(', ', $sums);
     return $sum;
 }
Ejemplo n.º 29
0
 /**
  * Gets the field names for the given table
  * $$$ hugh - added this to backend, as I need it in some places where we have
  * a backend list model, and until now only existed in the FE model.
  *
  * @param   string $tbl Table name
  * @param   string $key Field to key return array on
  *
  * @return  array  table fields
  */
 public function getDBFields($tbl = null, $key = null)
 {
     if (is_null($tbl)) {
         $table = $this->getTable();
         $tbl = $table->db_table_name;
     }
     if ($tbl == '') {
         return array();
     }
     $sig = $tbl . $key;
     $tbl = FabrikString::safeColName($tbl);
     if (!isset($this->dbFields[$sig])) {
         $db = $this->getDb();
         $tbl = FabrikString::safeColName($tbl);
         $db->setQuery("DESCRIBE " . $tbl);
         $this->dbFields[$sig] = $db->loadObjectList($key);
         /**
          * $$$ hugh - added BaseType, which strips (X) from things like INT(6) OR varchar(32)
          * Also converts it to UPPER, just to make things a little easier.
          */
         foreach ($this->dbFields[$sig] as &$row) {
             /**
              * Boil the type down to just the base type, so "INT(11) UNSIGNED" becomes just "INT"
              * I'm sure there's other cases than just UNSIGNED I need to deal with, but for now that's
              * what I most care about, as this stuff is being written handle being more specific about
              * the elements the list PK can be selected from.
              */
             $row->BaseType = strtoupper(preg_replace('#(\\(\\d+\\))$#', '', $row->Type));
             $row->BaseType = preg_replace('#(\\s+SIGNED|\\s+UNSIGNED)#', '', $row->BaseType);
             /**
              * Grab the size part ...
              */
             $matches = array();
             if (preg_match('#\\((\\d+)\\)$#', $row->Type, $matches)) {
                 $row->BaseLength = $matches[1];
             } else {
                 $row->BaseLength = '';
             }
         }
     }
     return $this->dbFields[$sig];
 }
Ejemplo n.º 30
0
 /**
  * date is stored in session com_fabrik.searchform.form'.$formModel->_id.'.filters
  * tablefilters looks up the com_fabrik.searchform.fromForm session var to then be able to pick up
  * the search form data
  * once its got it it unsets com_fabrik.searchform.fromForm so that the search values are not reused
  * (they are however stored in the session so behave like normal filters afterwards)
  * If the tablefilter does find the com_fabrik.searchform.fromForm var it won't use any session filters
  *
  * @param $formModel
  * @return unknown_type
  */
 function _storeInSession(&$formModel)
 {
     $app =& JFactory::getApplication();
     $store = array();
     if ($this->_data->save_in_session == '1') {
         //@TODO - rob, you need to look at this, I really only put this in as a band-aid.
         // $$$ hugh - we need to guesstimate the 'type', otherwise when the session data is processed
         // on table load as filters, everything will default to 'field', which borks up if (say) it's
         // really a dropdown
         /*
         foreach ($formModel->_formData as $key => $value) {
         	if ($formModel->hasElement($key)) {
         		//$value = urlencode(stripslashes($value));
         		$store[$formModel->_id]["$key"] = array('type'=>'', 'value'=>$value, 'match'=>false);
         	}
         }
         */
         $groups =& $formModel->getGroupsHiarachy();
         foreach ($groups as $group) {
             $elements =& $group->getPublishedElements();
             foreach ($elements as $element) {
                 if ($group->isJoin()) {
                     $tmpData = $formModel->_fullFormData['join'][$group->getGroup()->join_id];
                 } else {
                     $tmpData = $formModel->_fullFormData;
                 }
                 if ($element->getElement()->name == 'fabrik_table_filter_all') {
                     continue;
                 }
                 $name = $element->getFullName(false);
                 if (array_key_exists($name, $tmpData)) {
                     $value = $tmpData[$name];
                     $match = $element->getElement()->filter_exact_match;
                     if (!is_array($value)) {
                         $value = array($value);
                     }
                     $c = 0;
                     foreach ($value as $v) {
                         if (count($value) == 1 || $c == 0) {
                             $join = 'AND';
                             $grouped = false;
                         } else {
                             $join = 'OR';
                             $grouped = true;
                         }
                         if ($v != '') {
                             $store['join'][] = $join;
                             $store['key'][] = FabrikString::safeColName($name);
                             $store['condition'][] = '=';
                             $store['search_type'][] = 'search';
                             $store['access'][] = 0;
                             $store['grouped_to_previous'][] = $grouped;
                             $store['eval'][] = FABRIKFILTER_TEXT;
                             $store['required'][] = false;
                             $store['value'][] = $v;
                             $store['full_words_only'][] = false;
                             $store['match'][] = $match;
                             $store['hidden'][] = 0;
                             $store['elementid'][] = $element->getElement()->id;
                         }
                         $c++;
                     }
                 }
             }
         }
         $session =& JFactory::getSession();
         $registry =& $session->get('registry');
         //clear registry search form entries
         $key = 'com_fabrik.searchform';
         //test for this err - http://fabrikar.com/forums/showthread.php?t=14149&page=3
         if (is_a($registry, 'JRegistry')) {
             $registry->setValue($key, null);
         }
         //$session->destroy();
         $tableModel =& $formModel->getTableModel();
         //check for special fabrik_table_filter_all element!
         $searchAll = JRequest::getVar($tableModel->getTable()->db_table_name . '___fabrik_table_filter_all');
         $registry->setValue('com_fabrik.searchform.form' . $formModel->_id . '.searchall', $searchAll);
         $registry->setValue('com_fabrik.searchform.form' . $formModel->_id . '.filters', $store);
         $registry->setValue('com_fabrik.searchform.fromForm', $formModel->_id);
     }
 }