Esempio n. 1
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');
 }
Esempio n. 2
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);
            }
        }
    }
/**
 * 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);
        }
    }
}
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * Returns an array of history ids of history records that match the 
  * given query.
  */
 function findMatchingSnapshots($record, $query, $idsOnly = true)
 {
     $app =& Dataface_Application::getInstance();
     $htablename = $record->_table->tablename . '__history';
     if (!Dataface_Table::tableExists($htablename)) {
         return array();
     }
     $keys = $record->strvals(array_keys($record->_table->keys()));
     foreach ($keys as $key => $val) {
         $query[$key] = '=' . $val;
     }
     if ($idsOnly) {
         $qbuilder = new Dataface_QueryBuilder($htablename, $query);
         $sql = $qbuilder->select(array('history__id'), $query);
         $res = xf_db_query($sql, df_db());
         $ids = array();
         while ($row = xf_db_fetch_row($res)) {
             $ids[] = $row[0];
         }
         @xf_db_free_result($res);
         return $ids;
     } else {
         return df_get_records_array($htablename, $query);
     }
 }
Esempio n. 6
0
 function getBlackListed($emails)
 {
     if (!Dataface_Table::tableExists('dataface__email_blacklist')) {
         $this->createEmailTables(null, null);
     }
     if (!is_array($emails)) {
         $emails = array($emails);
     }
     $res = mysql_query("select email from dataface__email_blacklist where email in ('" . implode("','", array_map('addslashes', $emails)) . "')", df_db());
     $out = array();
     if (!$res) {
         trigger_error(mysql_error(df_db()), E_USER_ERROR);
     }
     while ($row = mysql_fetch_row($res)) {
         $out[] = $row[0];
     }
     @mysql_free_result($res);
     return $out;
 }
Esempio n. 7
0
 /**
  * Creates a table to hold the temporary user registrations.
  */
 function createRegistrationTable()
 {
     if (!Dataface_Table::tableExists('dataface__registrations', false)) {
         $sql = "create table `dataface__registrations` (\n\t\t\t\tregistration_code varchar(32) not null,\n\t\t\t\tregistration_date timestamp not null,\n\t\t\t\tregistration_data longtext not null,\n\t\t\t\tprimary key (registration_code)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
         // registration_code stores an md5 code used to identify the registration
         // registration_date is the date that the registration was made
         // registration_data is a serialized array of the data from getValues()
         // on the record.
         $res = xf_db_query($sql, df_db());
         if (!$res) {
             throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
         }
     }
     return true;
 }
Esempio n. 8
0
 function submitTranslation(&$record, $params = array())
 {
     if (!Dataface_Table::tableExists('dataface__translation_submissions', false)) {
         $this->createTranslationSubmissionsTable();
     }
     $trec = new Dataface_Record('dataface__translation_submissions', array());
     $trec->setValues($params);
     $trec->save();
 }