Exemplo n.º 1
0
 protected function getManagementJS($data = array())
 {
     global $Itemid;
     // $$$ rob ALWAYS load the calendar (so its avaible in ajax forms)
     FabrikHelperHTML::loadcalendar();
     $app =& JFactory::getApplication();
     $model =& $this->getModel();
     $table =& $model->getTable();
     $formModel =& $model->getForm();
     $elementsNotInTable =& $formModel->getElementsNotInTable();
     $keys = array('id' => '', 'name' => '', 'label' => '');
     foreach ($elementsNotInTable as &$i) {
         if (is_a($i, 'TableElement')) {
             $i = array_intersect_key($i->getPublicProperties(), $keys);
         }
     }
     FabrikHelperHTML::packageJS();
     $document =& JFactory::getDocument();
     if ($model->requiresSlimbox()) {
         FabrikHelperHTML::slimbox();
     }
     if ($model->requiresMocha()) {
         FabrikHelperHTML::mocha();
     }
     FabrikHelperHTML::script('table.js', 'media/com_fabrik/js/', true);
     $tmpl = $this->getTmpl();
     FabrikHelperHTML::stylesheet('table.css', 'media/com_fabrik/css/');
     // check for a custom css file and include it if it exists
     FabrikHelperHTML::stylesheetFromPath("components" . DS . "com_fabrik" . DS . "views" . DS . "table" . DS . "tmpl" . DS . $tmpl . DS . "template.css");
     //check and add a general fabrik custom css file overrides template css and generic table css
     FabrikHelperHTML::stylesheetFromPath("media" . DS . "com_fabrik" . DS . "css" . DS . "custom.css");
     //check and add a specific table template css file overrides template css generic table css and generic custom css
     FabrikHelperHTML::stylesheetFromPath("components" . DS . "com_fabrik" . DS . "views" . DS . "table" . DS . "tmpl" . DS . $tmpl . DS . "custom.css");
     // check for a custom js file and include it if it exists
     $aJsPath = JPATH_SITE . DS . "components" . DS . "com_fabrik" . DS . "views" . DS . "table" . DS . "tmpl" . DS . $tmpl . DS . "javascript.js";
     if (JFile::exists($aJsPath)) {
         FabrikHelperHTML::script("javascript.js", 'components/com_fabrik/views/table/tmpl/' . $tmpl . '/', true);
     }
     $origRows = $this->rows;
     $this->rows = array(array());
     $tmpItemid = !isset($Itemid) ? 0 : $Itemid;
     $this->_c = 0;
     $this->_row = new stdClass();
     $script = '';
     // $$$ rob done in HTMLHelper
     //$script = "/* <![CDATA[ */ \n";
     static $tableini;
     if (!$tableini) {
         $tableini = true;
         $script .= "var oTables = \$H();\n";
     }
     $opts = new stdClass();
     $opts->admin = $app->isAdmin();
     $opts->postMethod = $model->getPostMethod();
     $opts->filterMethod = $this->filter_action;
     $opts->form = 'tableform_' . $model->_id;
     $opts->headings = $model->_jsonHeadings();
     $labels = $this->headings;
     foreach ($labels as &$l) {
         $l = strip_tags($l);
     }
     $opts->labels = $labels;
     $opts->primaryKey = $table->db_primary_key;
     $opts->Itemid = $tmpItemid;
     $opts->formid = $model->_oForm->getId();
     $opts->canEdit = $model->canEdit() ? "1" : "0";
     $opts->canView = $model->canView() ? "1" : "0";
     $opts->page = JRoute::_('index.php');
     $opts->isGrouped = $this->isGrouped;
     $opts->mooversion = FabrikWorker::getMooVersion() == 1 ? 1.2 : 1.1;
     if (FabrikWorker::nativeMootools12()) {
         $opts->mooversion = 1.24;
     }
     $opts->formels = $elementsNotInTable;
     //if table data starts as empty then we need the html from the row
     // template otherwise we can't add a row to the table
     if ($model->_postMethod == 'ajax') {
         ob_start();
         $this->_row = new stdClass();
         $this->_row->id = '';
         $this->_row->class = 'fabrik_row';
         require COM_FABRIK_FRONTEND . DS . 'views' . DS . 'table' . DS . 'tmpl' . DS . 'default' . DS . 'default_row.php';
         $opts->rowtemplate = ob_get_contents();
         ob_end_clean();
     }
     //$$$rob if you are loading a table in a window from a form db join select record option
     // then we want to know the id of the window so we can set its showSpinner() method
     $opts->winid = JRequest::getVar('winid', '');
     $opts->ajaxEditViewLink = $model->ajaxEditViewLink() ? 1 : 0;
     $opts = json_encode($opts);
     $lang = new stdClass();
     $lang->select_rows = JText::_('SELECT SOME ROWS FOR DELETION');
     $lang->yes = JText::_('Yes');
     $lang->no = JText::_('No');
     $lang->select_colums_to_export = JText::_('SELECT_COLUMNS_TO_EXPORT');
     $lang->include_filters = JText::_('INCLUDE_FILTERS');
     $lang->include_data = JText::_('INCLUDE_DATA');
     $lang->inlcude_raw_data = JText::_('INCLUDE_RAW_DATA');
     $lang->include_calculations = JText::_('INLCUDE_CALCULATIONS');
     $lang->export = JText::_('EXPORT');
     $lang->loading = JText::_('loading');
     $lang->savingto = JText::_('Saving to');
     $lang->confirmDelete = JText::_('CONFIRMDELETE');
     $lang->csv_downloading = JText::_('COM_FABRIK_CSV_DOWNLOADING');
     $lang->download_here = JText::_('COM_FABRIK_DOWNLOAD_HERE');
     $lang->csv_complete = JText::_('COM_FABRIK_CSV_COMPLETE');
     $lang = json_encode($lang);
     $script .= "\n" . "var oTable{$model->_id} = new fabrikTable({$model->_id},";
     $script .= $opts . "," . $lang;
     $script .= "\n" . ");";
     $script .= "\n" . "oTable{$model->_id}.addListenTo('form_{$model->_oForm->_id}');";
     $script .= "\n" . "oTable{$model->_id}.addListenTo('table_{$model->_id}');";
     $script .= "\n" . "oPackage.addBlock('table_{$model->_id}', oTable{$model->_id});";
     //add in plugin objects
     $plugins = $this->get('PluginJsObjects');
     $script .= "\noTable{$model->_id}.addPlugins([\n";
     $script .= "  " . implode(",\n  ", $plugins);
     $script .= "]\n);\n";
     $script .= "oTables.set({$model->_id}, oTable{$model->_id});\n";
     FabrikHelperHTML::addScriptDeclaration($script);
     $this->getElementJs();
     //reset data back to original settings
     $this->rows = $origRows;
     $this->get('CustomJsAction');
 }
Exemplo n.º 2
0
 /**
  * Get the table filter for the element
  * @param int repeat group counter
  * @param bol 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
  */
 function &getFilter($counter, $normal = true)
 {
     $params =& $this->getParams();
     $listModel =& $this->getListModel();
     $table =& $listModel->getTable();
     $element = $this->getElement();
     $origTable = $table->db_table_name;
     $fabrikDb =& $listModel->getDb();
     $elName = $this->getFullName(false, true, false);
     $elName2 = $this->getFullName(false, false, false);
     $ids = $listModel->getColumnData($elName2);
     $v = 'fabrik___filter[list_' . $table->id . '][value][' . $counter . ']';
     //corect default got
     $default = $this->getDefaultFilterVal($normal, $counter);
     $format = $params->get('date_table_format', '%Y-%m-%d');
     $fromTable = $origTable;
     $joinStr = '';
     // $$$ hugh - in advanced search, _aJoins wasn't getting set
     $joins = $listModel->getJoins();
     foreach ($joins as $aJoin) {
         // not sure why the group id key wasnt 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;
                 $joinStr = " LEFT JOIN {$fromTable} ON " . $aJoin->table_join . "." . $aJoin->table_join_key . " = " . $aJoin->join_from_table . "." . $aJoin->table_key;
                 $elName = str_replace($origTable . '.', $fromTable . '.', $elName);
             }
         }
     }
     $where = $listModel->_buildQueryPrefilterWhere($this);
     $elName = FabrikString::safeColName($elName);
     //dont format here as the format string is different between mysql and php's calendar strftime
     $sql = "SELECT DISTINCT({$elName}) AS text, {$elName} AS value FROM `{$origTable}` {$joinStr}" . "\n WHERE {$elName} IN ('" . implode("','", $ids) . "')" . "\n AND TRIM({$elName}) <> '' {$where} GROUP BY text ASC";
     $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'];
         }
     }
     $htmlid = $this->getHTMLId();
     $tzoffset = new DateTimeZone(JFactory::getConfig()->get('offset'));
     if (in_array($element->filter_type, array('dropdown'))) {
         $rows = $this->filterValueList($normal);
     }
     $calOpts = array('class' => 'inputbox fabrik_filter', 'maxlength' => '19', 'size' => 16);
     switch ($element->filter_type) {
         case "range":
             FabrikHelperHTML::loadcalendar();
             //@TODO: this messes up if the table date format is different to the form date format
             if (empty($default)) {
                 $default = array('', '');
             }
             $v = 'fabrik___filter[table_' . $table->id . '][value][' . $counter . ']';
             $return = JText::_('COM_FABRIK_DATE_RANGE_BETWEEN') . $this->calendar($default[0], $v . '[0]', $this->getHTMLId() . "_filter_range_0_" . JRequest::getVar('task'), $format, $calOpts);
             $return .= "<br />" . JText::_('COM_FABRIK_DATE_RANGE_AND') . $this->calendar($default[1], $v . '[1]', $this->getHTMLId() . "_filter_range_1" . JRequest::getVar('task'), $format, $calOpts);
             break;
         case "dropdown":
             // cant do the format in the MySQL query as its not the same formatting
             // e.g. M in mysql is month and J's date code its minute
             jimport('joomla.utilities.date');
             $ddData = array();
             foreach ($rows as $k => $o) {
                 if ($fabrikDb->getNullDate() === $o->text) {
                     $o->text = '';
                     $o->value = '';
                 } else {
                     $d = new JDate($o->text);
                     //@TODO add an option as to whether we format values or not (if records as timestamps we don't want to format the filter value as running
                     // the filter will result in no records found. see http://fabrikar.com/forums/showthread.php?t=10964
                     $o->value = $d->toFormat($format);
                     //if we have a table format like %m-%d then we want to remove duplicate full times
                     $o->text = $d->toFormat($format);
                 }
                 if (!array_key_exists($o->value, $ddData)) {
                     $ddData[$o->value] = $o;
                 }
             }
             array_unshift($ddData, JHTML::_('select.option', '', $this->filterSelectLabel()));
             $return = JHTML::_('select.genericlist', $ddData, $v, 'class="inputbox fabrik_filter" size="1" maxlength="19"', 'value', 'text', $default, $htmlid . "_filter_range_0");
             break;
         default:
         case "field":
             FabrikHelperHTML::loadcalendar();
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return = $this->calendar($default, $v, $htmlid . "_filter_range_0_" . JRequest::getVar('task'), $format, $calOpts);
             break;
         case 'auto-complete':
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return = "<input type=\"hidden\" name=\"{$v}\" class=\"inputbox fabrik_filter\" value=\"{$default}\" id=\"{$htmlid}\" />";
             $return .= "<input type=\"text\" name=\"{$v}-auto-complete\" class=\"inputbox fabrik_filter autocomplete-trigger\" value=\"{$default}\" id=\"{$htmlid}-auto-complete\"  />";
             $autoId = $htmlid;
             if (!$normal) {
                 $autoId = '#advanced-search-table .autocomplete-trigger';
             }
             FabrikHelperHTML::autoComplete($autoId, $this->getElement()->id, 'date');
             break;
     }
     if ($normal) {
         $return .= $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return .= $this->getAdvancedFilterHiddenFields();
     }
     return $return;
 }
Exemplo n.º 3
0
 /**
  * Get the list filter for the element
  * @param int filter order
  * @param bol 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
  */
 function getFilter($counter, $normal = true)
 {
     $params = $this->getParams();
     $listModel = $this->getListModel();
     $table = $listModel->getTable();
     $element = $this->getElement();
     $origTable = $table->db_table_name;
     $fabrikDb = $listModel->getDb();
     $elName = $this->getFullName(false, true, false);
     $elName2 = $this->getFullName(false, false, false);
     $ids = $listModel->getColumnData($elName2);
     $v = $this->filterName($counter, $normal);
     //corect default got
     $default = $this->getDefaultFilterVal($normal, $counter);
     $format = $params->get('date_table_format', '%Y-%m-%d');
     $fromTable = $origTable;
     $joinStr = '';
     // $$$ hugh - in advanced search, _aJoins wasn't getting set
     $joins = $listModel->getJoins();
     foreach ($joins as $aJoin) {
         // not sure why the group id key wasnt 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;
                 $joinStr = " LEFT JOIN {$fromTable} ON " . $aJoin->table_join . "." . $aJoin->table_join_key . " = " . $aJoin->join_from_table . "." . $aJoin->table_key;
                 $elName = str_replace($origTable . '.', $fromTable . '.', $elName);
             }
         }
     }
     $where = $listModel->_buildQueryPrefilterWhere($this);
     $elName = FabrikString::safeColName($elName);
     //dont format here as the format string is different between mysql and php's calendar strftime
     $sql = "SELECT DISTINCT({$elName}) AS text, {$elName} AS value FROM `{$origTable}` {$joinStr}" . "\n WHERE {$elName} IN ('" . implode("','", $ids) . "')" . "\n AND TRIM({$elName}) <> '' {$where} GROUP BY text ASC";
     $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'];
         }
     }
     $htmlid = $this->getHTMLId();
     $timeZone = new DateTimeZone(JFactory::getConfig()->get('offset'));
     if (in_array($element->filter_type, array('dropdown'))) {
         $rows = $this->filterValueList($normal);
     }
     $calOpts = $this->filterCalendarOpts();
     $return = array();
     switch ($element->filter_type) {
         case "range":
             FabrikHelperHTML::loadcalendar();
             if (empty($default)) {
                 $default = array('', '');
             } else {
                 $default[0] = JFactory::getDate($default[0])->toFormat($format);
                 $default[1] = JFactory::getDate($default[1])->toFormat($format);
             }
             $return[] = JText::_('COM_FABRIK_DATE_RANGE_BETWEEN') . $this->calendar($default[0], $v . '[0]', $this->getHTMLId() . "_filter_range_0_" . JRequest::getVar('task'), $format, $calOpts);
             $return[] = '<br />' . JText::_('COM_FABRIK_DATE_RANGE_AND') . $this->calendar($default[1], $v . '[1]', $this->getHTMLId() . "_filter_range_1_" . JRequest::getVar('task'), $format, $calOpts);
             break;
         case "dropdown":
             // cant do the format in the MySQL query as its not the same formatting
             // e.g. M in mysql is month and J's date code its minute
             jimport('joomla.utilities.date');
             $ddData = array();
             foreach ($rows as $k => $o) {
                 if ($fabrikDb->getNullDate() === $o->text) {
                     $o->text = '';
                     $o->value = '';
                 } else {
                     $d = new FabDate($o->text);
                     $o->value = $d->toSql();
                     $o->text = $d->toFormat($format);
                 }
                 if (!array_key_exists($o->value, $ddData)) {
                     $ddData[$o->value] = $o;
                 }
             }
             array_unshift($ddData, JHTML::_('select.option', '', $this->filterSelectLabel()));
             $return[] = JHTML::_('select.genericlist', $ddData, $v, 'class="inputbox fabrik_filter" size="1" maxlength="19"', 'value', 'text', $default, $htmlid . "_filter_range_0");
             break;
         default:
         case "field":
             FabrikHelperHTML::loadcalendar();
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if ($default !== '') {
                 $default = JFactory::getDate($default)->toFormat($format);
             }
             $return[] = $this->calendar($default, $v, $htmlid . '_filter_range_0_' . JRequest::getVar('task'), $format, $calOpts);
             break;
         case 'hidden':
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return[] = '<input type="hidden" name="' . $v . '" class="inputbox fabrik_filter" value="' . $default . '" id="' . $htmlid . '" />';
             break;
         case 'auto-complete':
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return[] = '<input type="hidden" name="' . $v . '" class="inputbox fabrik_filter" value="' . $default . '" id="' . $htmlid . '" />';
             $return[] = '<input type="text" name="' . $v . '-auto-complete" class="inputbox fabrik_filter autocomplete-trigger" value="' . $default . '" id="' . $htmlid . '-auto-complete" />';
             $autoId = '#' . $htmlid . '-auto-complete';
             if (!$normal) {
                 $autoId = '#advanced-search-table .autocomplete-trigger';
             }
             FabrikHelperHTML::autoComplete($autoId, $this->getElement()->id, 'date');
             break;
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }
Exemplo n.º 4
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)
 {
     $params = $this->getParams();
     $listModel = $this->getListModel();
     $table = $listModel->getTable();
     $element = $this->getElement();
     $origTable = $table->db_table_name;
     $fabrikDb = $listModel->getDb();
     $elName = $this->getFullName(true, false);
     $elName2 = $this->getFullName(false, false);
     $v = $this->filterName($counter, $normal);
     $class = $this->filterClass();
     // Correct default got
     $default = $this->getDefaultFilterVal($normal, $counter);
     $format = $params->get('date_table_format', 'Y-m-d');
     $fromTable = $origTable;
     // $$$ 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'];
         }
     }
     $htmlid = $this->getHTMLId();
     $fType = $this->getFilterType();
     $timeZone = new DateTimeZone(JFactory::getConfig()->get('offset'));
     if (in_array($fType, array('dropdown', 'checkbox', 'multiselect'))) {
         $rows = $this->filterValueList($normal);
     }
     $calOpts = $this->filterCalendarOpts();
     $return = array();
     switch ($fType) {
         case 'checkbox':
             $return[] = $this->checkboxFilter($rows, $default, $v);
             break;
         case 'range':
         case 'range-hidden':
             FabrikHelperHTML::loadcalendar();
             if (empty($default)) {
                 $default = array('', '');
             } else {
                 $d = new FabDate($default[0]);
                 $default[0] = $d->format($format);
                 $d = new FabDate($default[1]);
                 $default[1] = $d->format($format);
             }
             // Add wrapper div for list filter toggling
             $return[] = '<div class="fabrik_filter_container">';
             if ($fType === 'range-hidden') {
                 $return[] = '<input type="hidden" name="' . $v . '[0]' . '" class="' . $class . '" value="' . $default[0] . '" id="' . $htmlid . '-0" />';
                 $return[] = '<input type="hidden" name="' . $v . '[1]' . '" class="' . $class . '" value="' . $default[1] . '" id="' . $htmlid . '-1" />';
                 $return[] = '</div>';
             } else {
                 $return[] = JText::_('COM_FABRIK_DATE_RANGE_BETWEEN') . $this->calendar($default[0], $v . '[0]', $this->getFilterHtmlId(0), $format, $calOpts);
                 $return[] = '<br />' . JText::_('COM_FABRIK_DATE_RANGE_AND') . $this->calendar($default[1], $v . '[1]', $this->getFilterHtmlId(1), $format, $calOpts);
                 $return[] = '</div>';
             }
             break;
         case 'dropdown':
         case 'multiselect':
             /**
              *  cant do the format in the MySQL query as its not the same formatting
              *  e.g. M in MySQL is month and J's date code its minute
              */
             $max = count($rows) < 7 ? count($rows) : 7;
             $size = $element->filter_type === 'multiselect' ? 'multiple="multiple" size="' . $max . '"' : 'size="1"';
             $v = $fType === 'multiselect' ? $v . '[]' : $v;
             jimport('joomla.utilities.date');
             $ddData = array();
             foreach ($rows as $k => $o) {
                 if ($fabrikDb->getNullDate() === $o->text) {
                     $o->text = '';
                     $o->value = '';
                 } else {
                     $d = new FabDate($o->text);
                     $d->setTimeZone($timeZone);
                     $o->value = $d->toSql(true);
                     $o->text = $d->format($format, true);
                 }
                 if (!array_key_exists($o->value, $ddData)) {
                     $ddData[$o->value] = $o;
                 }
             }
             array_unshift($ddData, JHTML::_('select.option', '', $this->filterSelectLabel()));
             $return[] = JHTML::_('select.genericlist', $ddData, $v, 'class="' . $class . '" ' . $size . ' maxlength="19"', 'value', 'text', $default, $htmlid . '0');
             break;
         default:
         case 'field':
             FabrikHelperHTML::loadcalendar();
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if ($default !== '') {
                 $d = new FabDate($default);
                 $default = $d->format($format);
             }
             // Add wrapper div for list filter toggling
             $return[] = '<div class="fabrik_filter_container">';
             $return[] = $this->calendar($default, $v, $this->getFilterHtmlId(0), $format, $calOpts);
             $return[] = '</div>';
             break;
         case 'hidden':
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             // Don't add id as caused issues with inline edit plugin and clashing ids.
             $return[] = '<input type="hidden" name="' . $v . '" class="' . $class . '" value="' . $default . '" />';
             break;
         case 'auto-complete':
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return[] = '<input type="hidden" name="' . $v . '" class="' . $class . '" value="' . $default . '" id="' . $htmlid . '" />';
             $return[] = '<input type="text" name="' . $v . '-auto-complete" class="' . $class . ' autocomplete-trigger" value="' . $default . '" id="' . $htmlid . '-auto-complete" />';
             $autoId = '#' . $htmlid . '-auto-complete';
             if (!$normal) {
                 $autoId = '.advanced-search-list .autocomplete-trigger';
             }
             FabrikHelperHTML::autoComplete($autoId, $this->getElement()->id, $this->getFormModel()->getId(), 'date');
             break;
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }
Exemplo n.º 5
0
 /**
  * append the form javascript into the document head
  * @param int table id
  */
 function _addJavascript($tableId)
 {
     // $$$ rob ALWAYS load the calendar (so its avaible in ajax forms)
     FabrikHelperHTML::loadcalendar();
     $app =& JFactory::getApplication();
     $document =& JFactory::getDocument();
     $model =& $this->getModel();
     $aLoadedElementPlugins = array();
     $jsActions = array();
     $jsControllerKey = $model->_editable ? 'form_' . $model->getId() : 'details_' . $model->getId();
     $allJsActions = $model->getJsActions();
     FabrikHelperHTML::packageJS();
     if (!defined('_JOS_FABRIK_FORMJS_INCLUDED')) {
         define('_JOS_FABRIK_FORMJS_INCLUDED', 1);
         FabrikHelperHTML::slimbox();
         FabrikHelperHTML::script('form.js', 'media/com_fabrik/js/', true);
         FabrikHelperHTML::script('element.js', 'media/com_fabrik/js/', true);
     }
     $aWYSIWYGNames = array();
     // $$$ hugh - yeat another one where if we =&, the $groups array pointer get buggered up and it
     // skips a group
     $groups = $model->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels =& $groupModel->getPublishedElements();
         foreach ($elementModels as $elementModel) {
             $res = $elementModel->useEditor();
             if ($res !== false) {
                 $aWYSIWYGNames[] = $res;
             }
             $eparams =& $elementModel->getParams();
             //load in once the element js class files
             // $$$ hugh - only needed getParent when we weren't saving changes to parent params to child
             // which we should now be doing ... and getParent() causes an extra table lookup for every child
             // element on the form.
             //$element =& $elementModel->getParent();
             $element =& $elementModel->getElement();
             if (!in_array($element->plugin, $aLoadedElementPlugins)) {
                 $aLoadedElementPlugins[] = $element->plugin;
                 $elementModel->formJavascriptClass();
             }
             $eventMax = $groupModel->_repeatTotal == 0 ? 1 : $groupModel->_repeatTotal;
             for ($c = 0; $c < $eventMax; $c++) {
                 $jsActions[] = $elementModel->getFormattedJSActions($allJsActions, $jsControllerKey, $c);
             }
         }
     }
     //new
     $actions = trim(implode("\n", $jsActions));
     //end new
     $params =& $model->getParams();
     $tableModel =& $model->getTableModel();
     $table =& $tableModel->getTable();
     $form =& $model->getForm();
     FabrikHelperHTML::mocha();
     $bkey = $model->_editable ? 'form_' . $model->getId() : 'details_' . $model->getId();
     FabrikHelperHTML::tips('.hasTip', array(), "\$('{$bkey}')");
     $key = FabrikString::safeColNameToArrayKey($table->db_primary_key);
     $this->get('FormCss');
     $this->get('CustomJsAction');
     //$startJs = "window.addEvent('domready', function() {\n";
     $startJs = "window.addEvent('" . FabrikHelperHTML::useLoadEvent() . "', function() {\n";
     $endJs = "});\n";
     $start_page = isset($model->sessionModel->last_page) ? (int) $model->sessionModel->last_page : 0;
     if ($start_page !== 0) {
         $app->enqueueMessage(JText::_('RESTARTINGMUTLIPAGEFORM'));
     } else {
         // form submitted but fails validation - needs to go to the last page
         $start_page = JRequest::getInt('currentPage', 0);
     }
     $opts = new stdClass();
     $opts->admin = $app->isAdmin();
     $opts->postMethod = $this->get('PostMethod');
     $opts->ajaxValidation = $params->get('ajax_validations');
     $opts->primaryKey = $key;
     $opts->liveSite = COM_FABRIK_LIVESITE;
     $opts->error = @$form->origerror;
     $opts->pages = $model->getPages();
     $opts->plugins = array();
     $opts->multipage_save = (bool) $model->saveMultiPage();
     $opts->editable = $model->_editable;
     $opts->start_page = $start_page;
     $opts->mooversion = FabrikWorker::getMooVersion() == 1 ? 1.2 : 1.1;
     //$$$rob dont int this as keys may be string
     $opts->rowid = $model->_rowId;
     //$$$rob if you are loading a table in a window from a form db join select record option
     // then we want to know the id of the window so we can set its showSpinner() method
     $opts->winid = JRequest::getVar('winid', '');
     //for editing groups with joined data and an empty joined record (ie no joined records)
     $hidden = array();
     $maxRepeat = array();
     $showMaxRepeats = array();
     $postedRepeatGroupCounts = (array) JRequest::getVar('fabrik_repeat_group');
     foreach ($this->groups as $g) {
         $hidden[$g->id] = $g->startHidden;
         if (JArrayHelper::getValue($postedRepeatGroupCounts, $g->id, 1) == 0) {
             $hidden[$g->id] = true;
         }
         $maxRepeat[$g->id] = $g->maxRepeat;
         $showMaxRepeats[$g->id] = $g->showMaxRepeats;
     }
     $opts->hiddenGroup = $hidden;
     $opts->maxRepeat = $maxRepeat;
     $opts->showMaxRepeats = $showMaxRepeats;
     //$$$ rob 26/04/2011 joomfish translations of password validation error messages
     $opts->lang = FabrikWorker::getJoomfishLang();
     // $$$ hugh adding these so calc element can easily find joined and repeated join groups
     // when it needs to add observe events ... don't ask ... LOL!
     $opts->join_group_ids = array();
     $opts->group_repeats = array();
     $opts->group_joins_ids = array();
     $groups =& $model->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         if ($groupModel->getGroup()->is_join) {
             $opts->join_group_ids[$groupModel->getGroup()->join_id] = (int) $groupModel->getGroup()->id;
             $opts->group_join_ids[$groupModel->getGroup()->id] = (int) $groupModel->getGroup()->join_id;
             $opts->group_repeats[$groupModel->getGroup()->id] = $groupModel->canRepeat();
         }
     }
     $opts = json_encode($opts);
     $lang = new stdClass();
     $lang->validation_altered_content = JText::_('VALIDATION_HAS_ALTERED_CONTENT');
     $lang->validating = JText::_('VALIDATING');
     $lang->success = JText::_('SUCCESS');
     $lang->nodata = JText::_('NOREPEATGROUPDATA');
     $lang->validation_error = JText::_('VALIDATION_ERROR');
     $lang->form_saved = JText::_('FORM_SAVED');
     $lang->confirmDelete = JText::_('CONFIRMDELETE');
     $lang = json_encode($lang);
     //$$$ rob dont declare as var $bkey, but rather assign to window, as if loaded via ajax window the function is wrapped
     // inside an anoymous function, and therefore $bkey wont be available as a global var in window
     $str = "window.{$bkey} = new fabrikForm(" . $model->getId() . ", {$opts}, {$lang});\n";
     $str .= "{$bkey}.addListenTo('table_" . $tableModel->getId() . "');\n";
     $str .= "{$bkey}.addListenTo('form_" . $model->getId() . "');\n";
     $str .= "if(\$type(window.oPackage) !== false) {\n";
     $str .= "oPackage.addBlock('{$bkey}', {$bkey});\n";
     $str .= "}\n";
     //instantaite js objects for each element
     $groupstr = '';
     $vstr = "\n";
     $str .= "{$startJs}";
     // $$$ rob in php5.2.6 (and possibly elsewhere) $groups's elements havent been updated
     // to contain the default value used by the element
     //foreach ($groups as $groupModel) {
     //testing this one again as Ive updated getGroupsHiarchy
     $str .= "{$bkey}.addElements({";
     foreach ($groups as $groupModel) {
         $showGroup = $groupModel->getParams()->get('repeat_group_show_first');
         if ($showGroup == -1 || $showGroup == 2 && $model->_editable) {
             // $$$ rob unpublished group so dont include the element js
             continue;
         }
         $aObjs = array();
         $elementModels =& $groupModel->getPublishedElements();
         // $$$ rob if _repeatTotal is 0 we still want to add the js objects as the els are only hidden
         $max = $groupModel->_repeatTotal > 0 ? $groupModel->_repeatTotal : 1;
         $str .= $groupModel->getGroup()->id . ":[";
         foreach ($elementModels as $elementModel) {
             $element =& $elementModel->getElement();
             if ($element->state == 0) {
                 continue;
             }
             $fullName = $elementModel->getFullName();
             $id = $elementModel->getHTMLId();
             $elementModel->_editable = $model->_editable;
             if ($elementModel->canUse() || $elementModel->canView()) {
                 for ($c = 0; $c < $max; $c++) {
                     // $$$ rob ensure that some js code has been returned otherwise dont add empty data to array
                     $ref = trim($elementModel->elementJavascript($c));
                     if ($ref !== '') {
                         $aObjs[] = $ref;
                     }
                     $validations =& $elementModel->getValidations();
                     if (!empty($validations) && $elementModel->_editable) {
                         $watchElements = $elementModel->getValidationWatchElements($c);
                         foreach ($watchElements as $watchElement) {
                             $vstr .= "{$bkey}.watchValidation('" . $watchElement['id'] . "', '" . $watchElement['triggerEvent'] . "');\n";
                         }
                     }
                 }
             }
         }
         $str .= implode(",\n", $aObjs);
         $str .= "],";
         $groupParams =& $groupModel->getParams();
         $addJs = str_replace('"', "'", $groupParams->get('repeat_group_js_add'));
         $addJs = str_replace(array("\n", "\r"), "", $addJs);
         $delJs = str_replace('"', "'", $groupParams->get('repeat_group_js_delete'));
         $gdelJs = str_replace(array("\n", "\r"), "", $delJs);
         if ($delJs !== '') {
             $groupstr .= "{$bkey}.addGroupJS(" . $groupModel->getId() . ", 'delete', \"{$delJs}\");\n";
         }
         if ($addJs !== '') {
             $groupstr .= "{$bkey}.addGroupJS(" . $groupModel->getId() . ", 'add', \"{$addJs}\");\n";
         }
     }
     $str = FabrikString::rtrimword($str, ',');
     $str .= "});\n";
     $str .= $groupstr;
     $str .= $actions;
     $str .= $vstr;
     $str .= $endJs;
     $str .= "function submit_form() {";
     if (!empty($aWYSIWYGNames)) {
         jimport('joomla.html.editor');
         $editor =& FabrikHelperHTML::getEditor();
         $str .= $editor->save('label');
         foreach ($aWYSIWYGNames as $parsedName) {
             $str .= $editor->save($parsedName);
         }
     }
     $str .= "\n\t\t\treturn false;\n\t\t}\n\n\t\tfunction submitbutton(button) {\n\t\t\tif (button==\"cancel\") {\n\t\t\t\tdocument.location = '" . JRoute::_('index.php?option=com_fabrik&task=viewTable&cid=' . $tableId) . "';\n\t\t\t}\n\t\t\tif (button == \"cancelShowForm\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n";
     FabrikHelperHTML::addScriptDeclaration($str);
     $pluginManager =& $model->getPluginManager();
     $pluginManager->runPlugins('onAfterJSLoad', $model);
     FabrikHelperHTML::mootools();
 }