function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     if (!@$_POST['-valuelist']) {
         echo JSON::error("No valuelist specified.");
         exit;
     }
     $valuelist = $_POST['-valuelist'];
     $query =& $app->getQuery();
     $table =& Dataface_Table::loadTable($query['-table']);
     if (!@$_POST['-value']) {
         echo JSON::error("No value was provided to be appended to the valuelist.");
         exit;
     }
     $value = $_POST['-value'];
     if (@$_POST['-key']) {
         $key = $_POST['-key'];
     } else {
         $key = null;
     }
     $vt =& Dataface_ValuelistTool::getInstance();
     $res = $vt->addValueToValuelist($table, $valuelist, $value, $key, true);
     if (PEAR::isError($res)) {
         echo JSON::error($res->getMessage());
         exit;
     }
     echo JSON::json(array('success' => 1, 'value' => array('key' => $res['key'], 'value' => $res['value'])));
     exit;
 }
Example #2
0
 function test_html()
 {
     $s =& Dataface_Table::loadTable('Profiles');
     $records = df_get_records_array('Profiles');
     $grid = new Dataface_dhtmlxGrid_grid($s->fields(), $records);
     echo $grid->toXML();
 }
 function handle($params)
 {
     session_write_close();
     header('Connection:close');
     $app = Dataface_Application::getInstance();
     $query = $app->getQuery();
     if (@$query['--id']) {
         $table = Dataface_Table::loadTable($query['-table']);
         $keys = array_keys($table->keys());
         if (count($keys) > 1) {
             throw new Exception("Table has compound key so its permissions cannot be retrieved with the --id parameter.");
         }
         $query[$keys[0]] = '=' . $query['--id'];
         $record = df_get_record($query['-table'], $query);
     } else {
         $record = $app->getRecord();
     }
     $perms = array();
     if ($record) {
         $perms = $record->getPermissions();
     }
     header('Content-type: application/json; charset="' . $app->_conf['oe'] . '"');
     $out = json_encode($perms);
     header('Content-Length: ' . strlen($out));
     echo $out;
     flush();
 }
 function Dataface_ValuelistEditorForm($tablename, $valuelistName, $widgetID = null)
 {
     $this->table =& Dataface_Table::loadTable($tablename);
     $this->valuelistName = $valuelistName;
     $this->values = $this->table->getValuelist($this->valuelistName);
     $this->widgetID = $widgetID;
 }
    /**
     * @brief Initializes the datepicker module and registers all of the event listener.
     *
     */
    function __construct()
    {
        $app = Dataface_Application::getInstance();
        // Now work on our dependencies
        $mt = Dataface_ModuleTool::getInstance();
        // We require the XataJax module
        // The XataJax module activates and embeds the Javascript and CSS tools
        $mt->loadModule('modules_XataJax', 'modules/XataJax/XataJax.php');
        // Register the geopicker widget with the form tool so that it responds
        // to widget:type=geopicker
        import('Dataface/FormTool.php');
        $ft = Dataface_FormTool::getInstance();
        $ft->registerWidgetHandler('geopicker', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widget.php', 'Dataface_FormTool_geopicker');
        if (!@$app->_conf['modules_geopicker'] or !@$app->_conf['modules_geopicker']['key']) {
            $msg = <<<END
                 <p>Google Maps Module is installed but no API key is specified.</p>
                 <p>For information about obtaining your API key see <a href="https://developers.google.com/maps/documentation/javascript/tutorial#api_key">this page</a>.</p>
                 <p>After obtaining your key, add the following section to your application's conf.ini file:</p>
                 <p><code><pre>
[modules_geopicker]
    key=YOUR_API_KEY_HERE
                    </pre></code></p>
END;
            die($msg);
        }
        $app->addHeadContent('<script>XF_GEOPICKER_API_KEY="' . htmlspecialchars($app->_conf['modules_geopicker']['key']) . '";</script>');
        foreach (Dataface_Table::loadTable('', df_db(), true) as $t) {
            $evt = new StdClass();
            $evt->table = $t;
            $this->afterTableInit($evt);
        }
        $app->registerEventListener("afterTableInit", array($this, 'afterTableInit'));
        $app->registerEventListener("Dataface_Record__htmlValue", array($this, 'Dataface_Record__htmlValue'));
    }
 function handle($params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     if (!isset($query['-relationship'])) {
         return PEAR::raiseError("No relationship specified.");
     }
     $table =& Dataface_Table::loadTable($query['-table']);
     $record =& $app->getRecord();
     if (!$record) {
         return Dataface_Error::permissionDenied("No record found");
     }
     $perms = $record->getPermissions(array('relationship' => $query['-relationship']));
     if (!@$perms['view related records']) {
         return Dataface_Error::permissionDenied('You don\'t have permission to view this relationship.');
     }
     $action = $table->getRelationshipsAsActions(array(), $query['-relationship']);
     if (isset($query['-template'])) {
         df_display(array('record' => $record), $query['-template']);
     } else {
         if (isset($action['template'])) {
             df_display(array('record' => $record), $action['template']);
         } else {
             df_display(array('record' => $record), 'Dataface_Related_Records_List.html');
         }
     }
 }
 function handle($params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $record =& $app->getRecord();
     if (!$record) {
         return PEAR::raiseError("No record found.", DATAFACE_E_NOTICE);
     }
     if (!isset($query['-relationship'])) {
         return PEAR::raiseError("No relationship specified.");
     }
     $table =& Dataface_Table::loadTable($query['-table']);
     $action = $table->getRelationshipsAsActions(array(), $query['-relationship']);
     if (@$action['permission'] and !$record->checkPermission($action['permission'])) {
         return Dataface_Error::permissionDenied();
     }
     ob_start();
     import('Dataface/RelationshipCheckboxForm.php');
     $form = new Dataface_RelationshipCheckboxForm($record, $query['-relationship']);
     $out = ob_get_contents();
     ob_end_clean();
     if (isset($query['-template'])) {
         df_display(array('form' => $out), $query['-template']);
     } else {
         if (isset($action['template'])) {
             df_display(array('form' => $out), $action['template']);
         } else {
             df_display(array('form' => $out), 'Dataface_related_records_checkboxes.html');
         }
     }
 }
Example #8
0
 function handle2($params)
 {
     $app = Dataface_Application::getInstance();
     $query = $app->getQuery();
     $table = $query['-table'];
     if (!@$query['-field']) {
         throw new Exception("No field specified", 500);
     }
     if (!@$query['-key']) {
         throw new Exception("No key specified", 500);
     }
     $tableObj = Dataface_Table::loadTable($table);
     if (PEAR::isError($tableObj)) {
         throw new Exception($tableObj->getMessage(), $tableObj->getCode());
     }
     $field =& $tableObj->getField($query['-field']);
     if (PEAR::isError($field)) {
         throw new Exception("Field not found " . $field->getMessage(), $field->getCode());
     }
     if (!@$field['vocabulary']) {
         throw new Exception("Field has no vocabulary assigned", 500);
     }
     $perms = $tableObj->getPermissions(array('field' => $field['name']));
     if (!@$perms['edit'] && !@$perms['new']) {
         throw new Exception("You don't have permission to access this vocabulary.", 400);
     }
     $valuelist = $tableObj->getValuelist($field['vocabulary']);
     if (PEAR::isError($valuelist)) {
         throw new Exception("Valuelist not found.", 404);
     }
     $value = @$valuelist[$query['-key']];
     df_write_json(array('code' => 200, 'message' => 'Found', 'value' => $value));
 }
Example #9
0
 function ReferenceBrowser($tablename, $relationshipName)
 {
     $this->_table =& Dataface_Table::loadTable($tablename);
     $this->_relationshipName = $relationshipName;
     $this->_relationship =& $this->_table->getRelationship($relationshipName);
     $this->HTML_QuickForm('Reference Browser');
 }
Example #10
0
 function test_add_value()
 {
     $vt = Dataface_ValuelistTool::getInstance();
     $people = Dataface_Table::loadTable('People');
     $vt->addValueToValuelist($people, 'Publications', 'My Test Publication');
     $res = xf_db_query("select * from Publications where `BiblioString` = 'My Test Publication'");
     $this->assertTrue(xf_db_num_rows($res) === 1);
 }
Example #11
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $this->table =& Dataface_Table::loadTable($query['-table']);
     $translations =& $this->table->getTranslations();
     foreach (array_keys($translations) as $trans) {
         $this->table->getTranslation($trans);
     }
     //print_r($translations);
     if (!isset($translations) || count($translations) < 2) {
         // there are no translations to be made
         trigger_error('Attempt to translate a record in a table "' . $this->table->tablename . '" that contains no translations.', E_USER_ERROR);
     }
     $this->translatableLanguages = array_keys($translations);
     $translatableLanguages =& $this->translatableLanguages;
     $this->languageCodes = new I18Nv2_Language($app->_conf['lang']);
     $languageCodes =& $this->languageCodes;
     $currentLanguage = $languageCodes->getName($app->_conf['lang']);
     if (count($translatableLanguages) < 2) {
         return PEAR::raiseError(df_translate('Not enough languages to translate', 'There aren\'t enough languages available to translate.'), DATAFACE_E_ERROR);
     }
     //$defaultSource = $translatableLanguages[0];
     //$defaultDest = $translatableLanguages[1];
     $options = array();
     foreach ($translatableLanguages as $lang) {
         $options[$lang] = $languageCodes->getName($lang);
     }
     unset($options[$app->_conf['default_language']]);
     $tt = new Dataface_TranslationTool();
     $form = new HTML_QuickForm('StatusForm', 'POST');
     $form->addElement('select', '--language', 'Translation', $options);
     $form->addElement('select', '--status', 'Status', $tt->translation_status_codes);
     //$form->setDefaults( array('-sourceLanguage'=>$defaultSource, '-destinationLanguage'=>$defaultDest));
     $form->addElement('submit', '--set_status', 'Set Status');
     foreach ($query as $key => $value) {
         $form->addElement('hidden', $key);
         $form->setDefaults(array($key => $value));
     }
     if ($form->validate()) {
         $res = $form->process(array(&$this, 'processForm'));
         if (PEAR::isError($res)) {
             return $res;
         } else {
             header('Location: ' . $app->url('-action=list&-sourceLanguage=&-destinationLanguage=&-translate=') . '&--msg=' . urlencode('Translation status successfully set.'));
             exit;
         }
     }
     ob_start();
     $form->display();
     $out = ob_get_contents();
     ob_end_clean();
     $records =& $this->getRecords();
     df_display(array('form' => $out, 'translationTool' => &$tt, 'records' => &$records, 'translations' => &$options, 'context' => &$this), 'Dataface_set_translation_status.html');
 }
 /**
  * Defines how a depselect widget should be built.
  *
  * @param Dataface_Record $record The Dataface_Record that is being edited.
  * @param array &$field The field configuration data structure that the widget is being generated for.
  * @param HTML_QuickForm The form to which the field is to be added.
  * @param string $formFieldName The name of the field in the form.
  * @param boolean $new Whether this widget is being built for a new record form.
  * @return HTML_QuickForm_element The element that can be added to a form.
  *
  */
 function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false)
 {
     $factory = Dataface_FormTool::factory();
     $mt = Dataface_ModuleTool::getInstance();
     $mod = $mt->loadModule('modules_depselect');
     //$atts = $el->getAttributes();
     $widget =& $field['widget'];
     $atts = array();
     if (!@$atts['class']) {
         $atts['class'] = '';
     }
     $atts['class'] .= ' xf-depselect';
     if (!@$atts['data-xf-table']) {
         $atts['data-xf-table'] = $field['tablename'];
     }
     $targetTable = Dataface_Table::loadTable($field['widget']['table']);
     if (PEAR::isError($targetTable)) {
         error_log("Your field {$formFieldName} is missing the widget:table directive or the table does not exist.");
         throw new Exception("Your field {$formFieldName} is missing the widget:table directive or the table does not exist.");
     }
     $targetPerms = $targetTable->getPermissions();
     $atts['data-xf-depselect-options-table'] = $field['widget']['table'];
     if (@$targetPerms['new']) {
         $atts['data-xf-depselect-perms-new'] = 1;
     }
     $atts['df:cloneable'] = 1;
     $jt = Dataface_JavascriptTool::getInstance();
     $jt->addPath(dirname(__FILE__) . '/js', $mod->getBaseURL() . '/js');
     $ct = Dataface_CSSTool::getInstance();
     $ct->addPath(dirname(__FILE__) . '/css', $mod->getBaseURL() . '/css');
     // Add our javascript
     $jt->import('xataface/widgets/depselect.js');
     $filters = array();
     if (@$field['widget']['filters'] and is_array($field['widget']['filters'])) {
         foreach ($field['widget']['filters'] as $key => $val) {
             $filters[] = urlencode($key) . '=' . urlencode($val);
         }
     }
     $atts['data-xf-depselect-filters'] = implode('&', $filters);
     if (@$field['widget']['nomatch']) {
         $atts['data-xf-depselect-nomatch'] = $field['widget']['nomatch'];
     }
     if (@$field['widget']['dialogSize']) {
         $atts['data-xf-depselect-dialogSize'] = $field['widget']['dialogSize'];
     }
     if (@$field['widget']['dialogMargin']) {
         $atts['data-xf-depselect-dialogMargin'] = $field['widget']['dialogMargin'];
     }
     //$el->setAttributes($atts);
     $el = $factory->addElement('depselect', $formFieldName, $widget['label'], $atts);
     if (PEAR::isError($el)) {
         throw new Exception($el->getMessage(), $el->getCode());
     }
     return $el;
 }
Example #13
0
 function test_table_permissions()
 {
     $pt =& Dataface_PermissionsTool::getInstance();
     $perms = $pt->getPermissions(Dataface_Table::loadTable('Profiles'));
     $this->assertEquals(array(1, 1, 1), array($perms['view'], $perms['edit'], $perms['delete']));
     $perms = $pt->getPermissions(Dataface_Table::loadTable('Profiles'), array('field' => 'fname'));
     $this->assertEquals(array(1, 1, 1), array($perms['view'], $perms['edit'], $perms['delete']));
     // varcharfield_checkboxes has view disabled in the fields.ini file
     $this->assertTrue(!$pt->view(Dataface_Table::loadTable('Test'), array('field' => 'varcharfield_checkboxes')));
     $this->assertTrue($pt->edit(Dataface_Table::loadTable('Test'), array('field' => 'varcharfield_checkboxes')));
 }
Example #14
0
 function Dataface_SortControl($fields, $prefix = '')
 {
     if (is_string($fields)) {
         $t =& Dataface_Table::loadTable($fields);
         $fields = array_keys($t->fields(false, true));
     } else {
         $app =& Dataface_Application::getInstance();
         $query =& $app->getQuery();
         $t =& Dataface_Table::loadTable($query['-table']);
     }
     $this->table =& $t;
     $this->fields = array();
     if (isset($t->_atts['__global__'])) {
         $globalProps = $t->_atts['__global__'];
     } else {
         $globalProps = array();
     }
     foreach ($fields as $field) {
         $fieldDef =& $t->getField($field);
         if (isset($globalProps['sortable']) and !$globalProps['sortable'] and !@$fieldDef['sortable']) {
             continue;
         } else {
             if (isset($fieldDef['sortable']) and !@$fieldDef['sortable']) {
                 continue;
             }
         }
         $this->fields[] = $field;
     }
     $this->prefix = $prefix;
     //$this->fields = $fields;
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     if (!isset($query['-' . $prefix . 'sort'])) {
         $sort = '';
     } else {
         $sort = $query['-' . $prefix . 'sort'];
     }
     $sort = array_map('trim', explode(',', $sort));
     $sort2 = array();
     foreach ($sort as $col) {
         if (!trim($col)) {
             continue;
         }
         $col = explode(' ', $col);
         if (count($col) <= 1) {
             $col[1] = 'asc';
         }
         $sort2[$col[0]] = $col[1];
     }
     // Now sort2 looks like array('col1'=>'asc', 'col2'=>'desc', etc...)
     $this->current_sort =& $sort2;
     $this->fields = array_diff($this->fields, array_keys($this->current_sort));
 }
Example #15
0
 function Dataface_DeleteForm($tablename, $db, $query)
 {
     $this->_tablename = $tablename;
     $this->_table =& Dataface_Table::loadTable($tablename);
     $this->_db = $db;
     $this->_query = $query;
     $this->_isBuilt = false;
     if (!isset($this->_query['-cursor'])) {
         $this->_query['-cursor'] = 0;
     }
     parent::HTML_QuickForm('deleteForm');
 }
Example #16
0
 function &getTable($uri)
 {
     if (strpos($uri, '?') !== false) {
         // We strip the fieldname off the end of the uri
         // because we only want to store one of each record.
         list($uri) = explode('?', $uri);
     }
     if (strpos($uri, '/') !== false) {
         list($uri) = explode('/', $uri);
     }
     return Dataface_Table::loadTable($uri);
 }
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     if (!@$_GET['history__id']) {
         return PEAR::raiseError('No history id supplied', DATAFACE_E_ERROR);
     }
     $historyid = $_GET['history__id'];
     $query =& $app->getQuery();
     $table = $query['-table'];
     import('Dataface/HistoryTool.php');
     $ht = new Dataface_HistoryTool();
     if (@$_GET['-show_changes']) {
         $record = $ht->getDiffs($table, $historyid);
     } else {
         $record = $ht->getRecordById($table, $historyid);
     }
     if (!$record) {
         return PEAR::raiseError("No history record for table {$table} with history id {$historyid} could be found", DATAFACE_E_ERROR);
     }
     if (PEAR::isError($record)) {
         return $record;
     }
     $context = array('history_record' => &$record);
     $context['table_record'] = new Dataface_Record($table, $record->vals());
     $t =& Dataface_Table::loadTable($table);
     $numfields = count($t->fields());
     $pts = 0;
     $ppf = array();
     foreach ($t->fields() as $field) {
         if ($t->isText($field['name'])) {
             $pts += 5;
             $ppf[$field['name']] = $pts;
         } else {
             $pts++;
             $ppf[$field['name']] = $pts;
         }
     }
     $firstField = null;
     $threshold = floatval(floatval($pts) / floatval(2));
     foreach ($t->fields() as $field) {
         if ($ppf[$field['name']] >= $threshold) {
             $firstField = $field['name'];
             break;
         }
     }
     $context['first_field_second_col'] = $firstField;
     $context['changes'] = @$_GET['-show_changes'];
     $context['table'] =& $t;
     df_display($context, 'Dataface_HistoryRecordDetails.html');
 }
Example #18
0
 /**
  * Creates a grid with the given id or a query.
  * @param mixed $query Either the grid id, or a query array.
  *
  */
 function Dataface_dhtmlxGrid_activegrid($query, $name = 'mygrid')
 {
     // We are building a grid from a Dataface Query array.
     $q =& $query;
     if (isset($q['-columns'])) {
         if (is_array($q['-columns'])) {
             $columns = $q['-columns'];
         } else {
             $columns = explode(',', $q['-columns']);
         }
     } else {
         $columns = null;
     }
     if (isset($q['-records'])) {
         $this->Dataface_dhtmlxGrid_grid($columns, $q['-records'], $name, $q['-parent_id'], $q['-relationship']);
     } else {
         if (isset($q['-relationship'])) {
             // We are looking at the related records of a particular record.
             $record = df_get_record($q['-table'], $q);
             $records = $record->getRelatedRecordObjects($q['-relationship']);
             // We want the keys to be unique identifiers for the record that it
             // points to, so we will rekey the array using the
             // Dataface_RelatedRecord::getId() method
             //$related_records = $this->keyById($related_records);
             if (!$columns) {
                 $table =& Dataface_Table::loadTable($q['-table']);
                 $relationship =& $table->getRelationship($q['-relationship']);
                 $columns = $relationship->getColumnNames();
             }
             $this->Dataface_dhtmlxGrid_grid($columns, $records, $name, $record->getId(), $q['-relationship']);
             // now that we have created the grid.. we need to generate
             // and id for it and save the data in session vars
         } else {
             // We are not looking for related records - we are looking for
             // actual records.
             $records = df_get_records_array($q['-table'], $q);
             // We want the keys to be unique identifiers for the record that
             // it points to, so we will rekey the array using the
             // Dataface_Record::getId() method.
             //$records = $this->keyById($records);
             if (!$columns) {
                 $table =& Dataface_Table::loadTable($q['-table']);
                 $columns = $table->fields();
             }
             $this->Dataface_dhtmlxGrid_grid($columns, $records, $name, $q['-table']);
         }
     }
     $this->id = $this->update(null);
 }
Example #19
0
 function Dataface_ResultController($tablename, $db = '', $baseUrl = '', $query = '')
 {
     $this->_tablename = $tablename;
     $this->_db = $db;
     $this->_baseUrl = $baseUrl ? $baseUrl : $_SERVER['PHP_SELF'];
     $app =& Dataface_Application::getInstance();
     $this->_table =& Dataface_Table::loadTable($this->_tablename);
     $this->_fields =& $this->_table->fields();
     if (!$query) {
         $this->_query =& $app->getQuery();
         $query =& $this->_query;
         $this->_queryBuilder = new Dataface_QueryBuilder($this->_query['-table'], $query);
         $this->_resultSet =& $app->getResultSet();
     } else {
         if (!is_array($query)) {
             $query = array("-mode" => $app->_conf['default_mode']);
         }
         $this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);
         if (!isset($query['-limit'])) {
             $query['-limit'] = $GLOBALS['Dataface_ResultController_limit'];
         }
         if (!isset($query['-skip'])) {
             $query['-skip'] = $GLOBALS['Dataface_ResultController_skip'];
         }
         if (!isset($query['-cursor'])) {
             $query['-cursor'] = $query['-skip'];
         }
         if (!isset($query['-mode'])) {
             $query['-mode'] = $app->_conf['default_mode'];
         }
         $this->_queryBuilder = new Dataface_QueryBuilder($this->_tablename, $query);
         $this->_query =& $this->_queryBuilder->_query;
     }
     // set the title column
     foreach ($this->_fields as $field) {
         if (preg_match('/char/i', $field['Type'])) {
             $this->_titleColumn = $field['name'];
             break;
         }
     }
     if (!isset($this->_titleColumn)) {
         reset($this->_fields);
         $field = current($this->_fields);
         $this->_titleColumn = $field['name'];
     }
     // set the position
     $this->_pos = $query['-cursor'];
     $this->_displayedRecords = $query['-limit'];
 }
Example #20
0
 function setUp()
 {
     parent::setUp();
     xf_db_query("CREATE TABLE `Pages` (\n\t\t\t`PageID` INT(11) auto_increment NOT NULL,\n\t\t\t`ParentID` INT(11),\n\t\t\t`ShortName` VARCHAR(32) NOT NULL,\n\t\t\t`Description` TEXT,\n\t\t\tPRIMARY KEY (`PageID`),\n\t\t\tUNIQUE (`ParentID`,`ShortName`))") or trigger_error(xf_db_error() . __LINE__);
     xf_db_query("INSERT INTO `Pages` (`PageID`,`ShortName`,`Description`)\n\t\t\tVALUES (1,'index_page','Main page')") or trigger_error(xf_db_error() . __LINE__);
     xf_db_query("INSERT INTO `Pages` (`ParentID`,`ShortName`,`Description`)\n\t\t\tVALUES \n\t\t\t(1,'about','About us'),\n\t\t\t(1,'jobs','Now hiring'),\n\t\t\t(1,'products','About our products'),\n\t\t\t(1,'services','About our services'),\n\t\t\t(1,'contact','Contact us')") or trigger_error(xf_db_error() . __LINE__);
     xf_db_query("INSERT INTO `Pages` (`ParentID`,`ShortName`,`Description`)\n\t\t\tVALUES\n\t\t\t(2,'history','Our history'),\n\t\t\t(2,'future', 'The direction of the company'),\n\t\t\t(3,'application', 'Job application'),\n\t\t\t(3,'current_listing', 'Current job listings'),\n\t\t\t(4,'awards','Product awards'),\n\t\t\t(4,'downloads','Product downlaods'),\n\t\t\t(5,'consultation','Free consultation')") or trigger_error(xf_db_error() . __LINE__);
     $table =& Dataface_Table::loadTable('Pages');
     $r =& $table->relationships();
     if (!isset($r['children'])) {
         $table->addRelationship('children', array('__sql__' => 'select * from Pages where ParentID=\'$PageID\'', 'meta:class' => 'children'));
     }
     $this->indexpage =& df_get_record('Pages', array('PageID' => 1));
     $this->t = new Dataface_TreeTable($this->indexpage);
 }
Example #21
0
 function handle(&$params)
 {
     import('Dataface/XMLTool.php');
     $xml = new Dataface_XMLTool();
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $table =& Dataface_Table::loadTable($query['-table']);
     echo $xml->header();
     $auth =& Dataface_AuthenticationTool::getInstance();
     echo "<![CDATA[";
     print_r($_SESSION);
     echo "]]>";
     echo "<user>" . $auth->getLoggedInUsername() . "</user>";
     echo $xml->toXML($table);
     //echo $xml->toXML($app->getRecord());
     echo $xml->toXML($app->getResultSet());
     echo $xml->footer();
     exit;
 }
Example #22
0
 function Dataface_ResultList($tablename, $db = '', $columns = array(), $query = array())
 {
     $app =& Dataface_Application::getInstance();
     $this->_tablename = $tablename;
     if (empty($db)) {
         $db = $app->db();
     }
     $this->_db = $db;
     $this->_columns = $columns;
     if (!is_array($columns)) {
         $this->_columns = array();
     }
     $this->_query = $query;
     if (!is_array($query)) {
         $this->_query = array();
     }
     $this->_table =& Dataface_Table::loadTable($tablename);
     $fieldnames = array_keys($this->_table->fields(false, true));
     $fields =& $this->_table->fields(false, true);
     if (count($this->_columns) == 0) {
         foreach ($fieldnames as $field) {
             if (@$fields[$field]['filter']) {
                 $this->_filterCols[] = $field;
             }
             if ($fields[$field]['visibility']['list'] != 'visible') {
                 continue;
             }
             if ($this->_table->isPassword($field)) {
                 continue;
             }
             if (isset($fields[$field]) and !preg_match('/blob/i', $fields[$field]['Type'])) {
                 $this->_columns[] = $field;
             }
         }
     } else {
         foreach ($fieldnames as $field) {
             if (@$fields[$field]['filter']) {
                 $this->_filterCols[] = $field;
             }
         }
     }
     $this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);
 }
Example #23
0
 public static function &getMask()
 {
     static $mask = -1;
     if ($mask == -1) {
         $app =& Dataface_Application::getInstance();
         $query =& $app->getQuery();
         $table =& Dataface_Table::loadTable($query['-table']);
         $mask = $_GET;
         //echo "GET: "; print_r($_GET);
         foreach ($query as $key => $value) {
             //if ( strpos($key,'--')!== 0 ){
             if (isset($table->_fields[$key]) or $key[0] == '-' and $key != '-new') {
                 //echo "Key $key";
                 $mask[$key] = $value;
             }
         }
         //print_r($mask);
     }
     return $mask;
 }
Example #24
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     // We need to load the current data grid from the database.
     // Its id is provided in the -gridid request parameter.
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     if (!@$query['-gridid']) {
         // No grid was specified.. so we will just take the first grid
         $grids = $mod->getDataGrids();
         if (!$grids) {
             // No grids were found.  We need to create one
             $table =& Dataface_Table::loadTable($query['-table']);
             $grid = $mod->createDataGrid($query['-table'] . ' default grid', $query['-table'], array_keys($table->fields()));
             $res = $mod->saveDataGrid($grid);
             if (PEAR::isError($res)) {
                 return $res;
             }
             $dataGrid =& $grid;
         } else {
             $dataGrid = $grids[0];
         }
     }
     if (PEAR::isError($dataGrid)) {
         return $dataGrid;
     }
     if (!@$dataGrid) {
         $dataGrid =& $mod->getDataGrid($query['-gridid']);
     }
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     $json = new Services_JSON();
     $jsonFieldDefs = $json->encode($dataGrid->getFieldDefs(true));
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     df_display(array('grid' => &$dataGrid, 'fieldDefs' => $jsonFieldDefs, 'json' => &$json), 'DataGrid/view.html');
 }
Example #25
0
 /**
  * @ingroup actions
  */
 function handle(&$params)
 {
     import('Dataface/FeedTool.php');
     $app =& Dataface_Application::getInstance();
     $ft = new Dataface_FeedTool();
     $query = $app->getQuery();
     if (@$query['-relationship']) {
         $record =& $app->getRecord();
         $perms = $record->getPermissions(array('relationship' => $query['-relationship']));
         if (!@$perms['related records feed']) {
             return Dataface_Error::permissionDenied('You don\'t have permission to view this relationship.');
         }
     }
     header("Content-Type: application/xml; charset=" . $app->_conf['oe']);
     $conf = $ft->getConfig();
     $query['-skip'] = 0;
     if (!isset($query['-sort']) and !@$query['-relationship']) {
         $table =& Dataface_Table::loadTable($query['-table']);
         $modifiedField = $table->getLastUpdatedField(true);
         if ($modifiedField) {
             $query['-sort'] = $modifiedField . ' desc';
         }
     }
     if (!isset($query['-limit']) and !@$query['-relationship']) {
         $default_limit = $conf['default_limit'];
         if (!$default_limit) {
             $default_limit = 60;
         }
         $query['-limit'] = $default_limit;
     }
     if (isset($query['--format'])) {
         $format = $query['--format'];
     } else {
         $format = 'RSS1.0';
     }
     echo $ft->getFeedXML($query, $format);
     exit;
 }
Example #26
0
 /**
  * Creates a new translation form.
  * @param $record Reference to Dataface_Record object to be translated.
  * @param $source The 2-digit language code of the source language.
  * @param $dest The 2-digit language code of the destination language.
  * @param $fieldnames Optional array of fields that are to be translated.
  *        By default all translatable fields will be translated.
  */
 function Dataface_TranslationForm(&$record, $source = null, $dest = null, $query = '', $fieldnames = null)
 {
     $app =& Dataface_Application::getInstance();
     if (is_string($record)) {
         // $record is just the name of a table.
         $table =& Dataface_Table::loadTable($record);
     } else {
         $table =& $record->_table;
     }
     $translations =& $table->getTranslations();
     foreach (array_keys($translations) as $trans) {
         $table->getTranslation($trans);
     }
     //print_r($translations);
     if (!isset($translations) || count($translations) < 2) {
         // there are no translations to be made
         throw new Exception(df_translate('scripts.Dataface.TranslationForm.ERROR_NO_TRANSLATIONS', 'Attempt to translate a record in a table "' . $table->tablename . '" that contains no translations.', array('table' => $table->tablename)), E_USER_ERROR);
     }
     $this->translatableLanguages = array_keys($translations);
     $source = isset($source) ? $source : $this->translatableLanguages[0];
     $dest = isset($dest) ? $dest : $this->translatableLanguages[1];
     $i = 0;
     while ($dest == $source) {
         if ($i > count($this->translatableLanguages) - 1) {
             throw new Exception("Failed to find an eligible language to translate to.");
         }
         $dest = $this->translatableLanguages[$i++];
     }
     $this->sourceLanguage = $source;
     $this->destinationLanguage = $dest;
     $this->_dest_translatedFields = $translations[$this->destinationLanguage];
     $this->Dataface_QuickForm($record, '', $query, 'translation_form', false, $fieldnames, $this->destinationLanguage);
     $this->_renderer->elementTemplate = 'Dataface_TranslationForm_element.html';
     $this->_renderer->groupeElementTemplate = 'Dataface_TranslationForm_groupelement.html';
     $this->loadRecords();
     // loads all of the translations from the database.
 }
Example #27
0
 /**
  * Refreshes the metadata table for a given table.  This means that missing
  * columns and keys are created so that the schema matches the schema of
  * the current table structure.
  *
  * @param string $tablename The name of the table for which the metadata is being
  *					 stored.
  */
 function refreshMetadataTable($tablename = null)
 {
     if (!isset($tablename)) {
         $tablename = $this->tablename;
     }
     if (Dataface_MetadataTool::isMetadataTable($tablename)) {
         return false;
     }
     $app =& Dataface_Application::getInstance();
     $table =& Dataface_Table::loadTable($tablename);
     $md_tablename = $tablename . '__metadata';
     if (!Dataface_Table::tableExists($md_tablename, false)) {
         if ($this->createMetadataTable($tablename)) {
             return true;
         }
     }
     $cols =& $this->getColumns($tablename, false);
     // First we have to go through all of the key fields of the subject table
     // and make sure that they appear in the metadata table.
     $updatePrimaryKey = false;
     foreach ($table->keys() as $field) {
         if (!isset($cols[$field['Field']])) {
             $updatePrimaryKey = true;
             $default = @$field['Default'] ? " DEFAULT {$field['Default']}" : '';
             $sql = "alter table `{$md_tablename}` add column `{$field['Field']}` {$field['Type']}{$default}";
             $res = xf_db_query($sql, $app->db());
             if (!$res) {
                 trigger_error(xf_db_error($app->db()), E_USER_ERROR);
             }
         }
     }
     $table_keys =& $table->keys();
     //Next we have to go through all of the key fields in the metadata table ane make sure that they
     // appear in the subject table primary keys.
     foreach ($this->getKeyColumns($tablename, false) as $field) {
         if (!isset($table_keys[$field['Field']])) {
             $updatePrimaryKey = true;
             $sql = "alter table `{$md_tablename}` drop column `{$field['Field']}`";
             $res = xf_db_query($sql, $app->db());
             if (!$res) {
                 trigger_error(xf_db_error($app->db()), E_USER_ERROR);
             }
         }
     }
     // If the primary key needed to be updated, we will update it now.
     if ($updatePrimaryKey) {
         // The primary key needs to be updated
         $sql = "drop primary key";
         @xf_db_query($sql, $app->db());
         $sql = "alter table `{$md_tablename}` add primary key (`" . implode('`,`', array_keys($table->keys())) . "`)";
         $res = xf_db_query($sql, $app->db());
         if (!$res) {
             trigger_error(xf_db_error($app->db()), E_USER_ERROR);
         }
     }
     // Now we need to make sure that all of the prescribed meta fields are
     // in the metadata field.
     $fielddefs = $this->loadMetadataFieldDefs($tablename);
     $cols = $this->getColumns($tablename, false);
     foreach ($fielddefs as $field) {
         if (!isset($cols[$field['Field']])) {
             $default = @$field['Default'] ? " DEFAULT {$field['Default']}" : '';
             $sql = "alter table `{$md_tablename}` add column `{$field['Field']}` {$field['Type']}{$default}";
             $res = xf_db_query($sql, $app->db());
             if (!$res) {
                 trigger_error(xf_db_error($app->db()), E_USER_ERROR);
             }
         }
     }
     return true;
 }
Example #28
0
 function handle(&$params)
 {
     set_time_limit(0);
     import('Dataface/RecordReader.php');
     $app =& Dataface_Application::getInstance();
     $query = $app->getQuery();
     $query['-limit'] = 9999999;
     $table =& Dataface_Table::loadTable($query['-table']);
     if (isset($query['-relationship']) and @$query['--related']) {
         $query['-related:start'] = 0;
         $query['-related:limit'] = 9999999;
         $record =& $app->getRecord();
         $relationship =& $table->getRelationship($query['-relationship']);
         $records =& df_get_related_records($query);
         //$record->getRelatedRecordObjects($query['-relationship']);
         $data = array();
         $headings = array();
         foreach ($relationship->_schema['short_columns'] as $colhead) {
             $f =& $relationship->getField($colhead);
             if (@$f['visibility']['csv'] == 'hidden') {
                 unset($f);
                 continue;
             }
             $headings[] = $colhead;
             unset($f);
         }
         $data[] = $headings;
         foreach ($records as $record) {
             if (!$record->checkPermission('view')) {
                 continue;
             }
             $data[] = $this->related_rec2data($record);
         }
         $temp = tmpfile();
         $this->startFile($temp, $query);
         foreach ($data as $row) {
             $this->writeRow($temp, $row, $query);
             //, $recordfputcsv($temp, $row,",",'"');
         }
     } else {
         $temp = tmpfile();
         $query['-skip'] = 0;
         $query['-limit'] = null;
         $records = new Dataface_RecordReader($query, 30, false);
         //$records =& df_get_records_array($query['-table'], $query,null,null,false);
         //$data = array();
         $headings = array();
         //foreach (array_merge(array_keys($table->fields()), array_keys($table->graftedFields())) as $colhead){
         foreach (array_keys($table->fields(false, true)) as $colhead) {
             $f =& $table->getField($colhead);
             if (@$f['visibility']['csv'] == 'hidden') {
                 unset($f);
                 continue;
             }
             $headings[] = $colhead;
             unset($f);
         }
         //$data[] = $headings;
         $this->startFile($temp, $query);
         $this->writeRow($temp, $headings, $query);
         //fputcsv($temp, $headings,",",'"');
         foreach ($records as $record) {
             if (!$record->checkPermission('view')) {
                 continue;
             }
             $data = $this->rec2data($record);
             //fputcsv($temp, $data,",",'"');
             $this->writeRow($temp, $data, $query);
         }
     }
     $this->endFile($temp, $query);
     fseek($temp, 0);
     $this->writeOutput($temp, $query);
     exit;
 }
Example #29
0
 function Dataface_TableTool($tablename)
 {
     $this->_table =& Dataface_Table::loadTable($tablename);
     $this->_app =& Dataface_Application::getInstance();
 }
 function handle(&$params)
 {
     session_write_close();
     header('Connection: close');
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $table = $query['-table'];
     $ids = $query['-id'];
     $rec = null;
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $out = array();
     foreach ($ids as $id) {
         if (preg_match('/^' . preg_quote($table, '/') . '\\?/', $id)) {
             // This is a record id
             $rec = df_get_record_by_id($id);
         } else {
             if (strpos($id, '=') !== false) {
                 parse_str($id, $q);
                 $rec = df_get_record($table, $q);
             } else {
                 $keys = array_keys(Dataface_Table::loadTable($table)->keys());
                 $q = array($keys[0] => '=' . $id);
                 $rec = df_get_record($table, $q);
             }
         }
         if ($rec) {
             header('Content-type: text/html; charset=' . $app->_conf['oe']);
             if ($rec->checkPermission('view')) {
                 switch (strval(@$query['-text'])) {
                     case '':
                     case '__title__':
                         $out[] = $rec->getTitle();
                         break;
                     case '__json__':
                         //header('Content-type: text/json; charset='.$app->_conf['oe']);
                         $out[] = array_merge($rec->strvals(), array('__id__' => $rec->getId()));
                         break;
                     default:
                         $out[] = $rec->display($query['-text']);
                         break;
                 }
             } else {
                 return Dataface_Error::permissionDenied('You require view permission to access this record');
             }
         }
     }
     if (count($out) == 0) {
         $out[] = "";
     }
     if (count($out) < 2 and !is_array($query['-id']) and @$query['-return-type'] != 'array') {
         if (@$query['-text'] == '__json__') {
             header("Content-type: application/json; charset=" . $app->_conf['oe']);
             echo json_encode($out[0]);
         } else {
             echo $out[0];
         }
     } else {
         header("Content-type: application/json; charset=" . $app->_conf['oe']);
         echo json_encode($out);
     }
     exit;
 }