Example #1
0
 function init(Dataface_Table $table)
 {
     if (!@Dataface_Application::getInstance()->_conf['enable_static']) {
         $efl =& $table->getField('enable_live_translation');
         $efl['Default'] = 1;
         $efl['widget']['type'] = 'hidden';
     }
 }
Example #2
0
 function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false)
 {
     /*
      *
      * This field uses a table widget.
      *
      */
     $table =& $record->_table;
     $formTool =& Dataface_FormTool::getInstance();
     $factory =& Dataface_FormTool::factory();
     $widget =& $field['widget'];
     $el =& $factory->addElement('table', $formFieldName, $widget['label']);
     if (isset($widget['fields'])) {
         $widget_fields =& $widget['fields'];
         foreach ($widget_fields as $widget_field) {
             $widget_field =& Dataface_Table::getTableField($widget_field, $this->db);
             if (PEAR::isError($widget_field)) {
                 return $widget_field;
             }
             $widget_widget = $formTool->buildWidget($record, $widget_field, $factory, $widget_field['name']);
             $el->addField($widget_widget);
         }
     } else {
         if (isset($field['fields'])) {
             foreach (array_keys($field['fields']) as $field_key) {
                 $widget_widget = $formTool->buildWidget($record, $field['fields'][$field_key], $factory, $field['fields'][$field_key]['name']);
                 $el->addField($widget_widget);
                 unset($widget_widget);
             }
         }
     }
     return $el;
 }
Example #3
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $record =& $app->getRecord();
     $context = array();
     if (!$record) {
         return PEAR::raiseError("No record is currently selected", DATAFACE_E_ERROR);
     }
     $history_tablename = $record->_table->tablename . '__history';
     if (!Dataface_Table::tableExists($history_tablename)) {
         $context['error'] = PEAR::raiseError("This record has no history yet recorded.", DATAFACE_E_NOTICE);
     } else {
         import('Dataface/HistoryTool.php');
         $history_tool = new Dataface_HistoryTool();
         $history_log = $history_tool->getHistoryLog($record);
         $context['log'] =& $history_log;
         // let's make a query string for the current record
         //current_record_qstr
         $keys = array_keys($record->_table->keys());
         $qstr = array();
         foreach ($keys as $key) {
             $qstr[] = urlencode('--__keys__[' . $key . ']') . '=' . urlencode($record->strval($key));
         }
         $context['current_record_qstr'] = implode('&', $qstr);
     }
     df_display($context, 'Dataface_RecordHistory.html');
 }
Example #4
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));
 }
 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 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;
 }
 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 #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_html()
 {
     $s =& Dataface_Table::loadTable('Profiles');
     $records = df_get_records_array('Profiles');
     $grid = new Dataface_dhtmlxGrid_grid($s->fields(), $records);
     echo $grid->toXML();
 }
    /**
     * @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'));
    }
Example #12
0
 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;
 }
Example #13
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 #14
0
    function handle(&$params)
    {
        $app =& Dataface_Application::getInstance();
        $tt = new Dataface_TranslationTool();
        if (!Dataface_Table::tableExists('dataface__translation_submissions', false)) {
            $tt->createTranslationSubmissionsTable();
            header('Location: ' . $app->url(''));
            exit;
        }
        if (!@$_POST['--submit']) {
            df_display(array('query' => $app->getQuery(), 'success' => @$_REQUEST['--success']), 'Dataface_submit_translation.html');
            exit;
        } else {
            if (@$_POST['subject']) {
                // This is a dummy field - possible hacking attempt
                header('Location: ' . $app->url('-action=list'));
                exit;
            }
            if (@$_POST['--recordid']) {
                $record = df_get_record_by_id($_POST['--recordid']);
                $values = array('record_id' => @$_POST['--recordid'], 'language' => @$_POST['--language'], 'url' => @$_POST['--url'], 'original_text' => @$_POST['--original_text'], 'translated_text' => @$_POST['--translated_text'], 'translated_by' => @$_POST['--translated_by']);
                $trec = new Dataface_Record('dataface__translation_submissions', array());
                $trec->setValues($values);
                $trec->save();
                $email = <<<END
 The following translation was submitted to the web site {$app->url('')}:
 
 Translation for record {$record->getTitle()} which can be viewed at {$record->getURL('-action=view')}.
 This translation was submitted by {$_POST['--translated_by']} after viewing the content at {$_POST['--url']}.
 
 The original text that was being translated is as follows:
 
 {$_POST['--original_text']}
 
 The translation proposed by this person is as follows:
 
 {$_POST['--translated_text']}
 
 For more details about this translation, please visit {$trec->getURL('-action=view')}.
END;
                if (@$app->_conf['admin_email']) {
                    mail($app->_conf['admin_email'], 'New translation submitted', $email);
                }
                if (@$_POST['--redirect'] || @$_POST['--url']) {
                    $url = @$_POST['--redirect'] ? $_POST['--redirect'] : $_POST['--url'];
                    header('Location: ' . $url . '&--msg=' . urlencode('Thank you for your submission.'));
                    exit;
                } else {
                    header('Location: ' . $app->url('') . '&--success=1&--msg=' . urlencode('Thank you for your submission.'));
                    exit;
                }
            } else {
                trigger_error("No record id was provided", E_USER_ERROR);
            }
        }
    }
Example #15
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 #17
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')));
 }
/**
 * A method to create the configuration table in the database.  The configuration
 * table is where configuration (e.g. fields.ini etc..) may be stored.  This is
 * a new feature in 0.6.14.
 *
 * @author Steve Hannah <*****@*****.**>
 * @created Feb. 26, 2007
 */
function Dataface_ConfigTool_createConfigTable()
{
    $self =& Dataface_ConfigTool::getInstance();
    if (!Dataface_Table::tableExists($self->configTableName, false)) {
        $sql = "CREATE TABLE `" . $self->configTableName . "` (\n\t\t\t\t\tconfig_id int(11) NOT NULL auto_increment primary key,\n\t\t\t\t\t`file` varchar(255) NOT NULL,\n\t\t\t\t\t`section` varchar(128),\n\t\t\t\t\t`key` varchar(128) NOT NULL,\n\t\t\t\t\t`value` text NOT NULL,\n\t\t\t\t\t`lang` varchar(2),\n\t\t\t\t\t`username` varchar(32),\n\t\t\t\t\t`priority` int(5) default 5\n\t\t\t\t\t)";
        $res = xf_db_query($sql, df_db());
        if (!$res) {
            throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
        }
    }
}
Example #19
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 #20
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 #21
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 #23
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 #24
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 #25
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 #26
0
 function handle(&$params)
 {
     session_write_close();
     set_time_limit(0);
     import('Dataface/Index.php');
     $index = new Dataface_Index();
     if (@$_POST['--build-index']) {
         if (is_array($_POST['--tables'])) {
             $tables = $_POST['--tables'];
         } else {
             if (!empty($_POST['--tables'])) {
                 $tables = array($_POST['--tables']);
             } else {
                 $tables = null;
             }
         }
         if (@$_POST['--clear']) {
             $clear = true;
         } else {
             $clear = false;
         }
         $index->buildIndex($tables, '*', $clear);
         $app =& Dataface_Application::getInstance();
         header('Location: ' . $app->url('') . '&--msg=' . urlencode('Successfully indexed database'));
         exit;
     }
     $tables = array_keys(Dataface_Table::getTableModificationTimes());
     $count = 0;
     $indexable = array();
     foreach ($tables as $key => $table) {
         if (preg_match('/^dataface__/', $table)) {
             continue;
         }
         if (preg_match('/^_/', $table)) {
             continue;
         }
         if ($index->isTableIndexable($table)) {
             $indexable[] = $table;
             //unset($tables[$key]);
         }
     }
     $tables = $indexable;
     df_display(array('tables' => $tables), 'manage_build_index.html');
 }
Example #27
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 #28
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 #29
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 #30
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');
 }