Exemplo n.º 1
0
 function _init_fields()
 {
     if (!empty($this->_fields)) {
         return $this->_fields;
     }
     $modin = $this->getModin();
     if (!$modin) {
         return false;
     }
     $sourceDef = get_class($this) . $modin;
     //check registry for field defs
     $reg =& AMP_Registry::instance();
     $definedSources =& $reg->getEntry(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS);
     if (!$definedSources) {
         $definedSources = AMP_cache_get(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS);
     }
     if ($definedSources && isset($definedSources[$sourceDef])) {
         return $definedSources[$sourceDef];
     }
     require_once 'AMP/System/UserData.php';
     $moduleSource = new AMPSystem_UserData($this->dbcon, $modin);
     if (!$moduleSource->hasData()) {
         return false;
     }
     $md = $moduleSource->getData();
     $fields = $this->_allowed_keys;
     $keys = array('label', 'public', 'type', 'required', 'values', 'lookup', 'size', 'enabled');
     foreach ($fields as $fname) {
         if (!$fname) {
             continue;
         }
         if (!(isset($md['enabled_' . $fname]) && $md['enabled_' . $fname])) {
             continue;
         }
         $field = array();
         foreach ($keys as $key) {
             $field[$key] = $md[$key . "_" . $fname];
         }
         $field = $this->_register_lookups($field);
         $this->_fields[$fname] = $field;
     }
     //Publish Field Hack
     if ($md['publish']) {
         $publish_field = array('type' => 'checkbox', 'label' => '<span class=publish_label>PUBLISH</span>', 'required' => false, 'public' => false, 'values' => 0, 'size' => null, 'enabled' => true);
         $this->_fields['publish'] = $publish_field;
     }
     //cache field defs to registry
     $definedSources[$sourceDef] = $this->_fields;
     $reg->setEntry(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS, $definedSources);
     AMP_cache_set(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS, $definedSources);
     return $this->_fields;
 }
Exemplo n.º 2
0
 function _make_new_quiz_form($data, $fieldname)
 {
     if (!(isset($data[$fieldname]) && $data[$fieldname])) {
         $new_form = new AMPSystem_UserData(AMP_Registry::getDbcon());
         $new_form->setDefaults();
         $new_form->mergeData(array('name' => $data['name'], 'publish_form' => $data['publish']));
         $new_form->save();
         $udm = new UserDataInput(AMP_Registry::getDbcon(), $new_form->id, true);
         $read_plugin =& $udm->registerPlugin("AMP", 'Save');
         $read_plugin->saveRegistration('AMP', 'Save');
         $save_plugin =& $udm->registerPlugin('AMP', 'Read');
         $save_plugin->saveRegistration('AMP', 'Read');
     } else {
         $udm = new UserDataInput(AMP_Registry::getDbcon(), $data[$fieldname], true);
     }
     $this->_udm =& $udm;
     $override_plugin =& $udm->registerPlugin("QuickForm", 'Override');
     if (!$override_plugin->plugin_instance) {
         $override_plugin->saveRegistration('QuickForm', 'Override');
         $override_plugin->saveOption('override_file', "form.{$udm->instance}.quiz.xml");
     }
     return $udm->instance;
 }
Exemplo n.º 3
0
function udm_amp_save_admin(&$udm, $options = array())
{
    $dbcon = $udm->dbcon;
    #$udm->doPlugin( 'AMP', 'FixupDB' );
    // Insert or Update?
    if (isset($udm->instance)) {
        $sql = "UPDATE userdata_fields SET ";
        $frmFieldValues = array_keys($udm->_module_def);
        $skipFields = array();
        foreach ($frmFieldValues as $field) {
            if (substr($field, 0, 5) == "core_") {
                $skipFields[] = substr($field, 5);
            }
        }
        foreach ($frmFieldValues as $field) {
            if (array_search($field, $skipFields)) {
                continue;
            }
            $sql_field = $field;
            if ($field == 'id') {
                continue;
            }
            if (substr($field, 0, 5) == "core_") {
                $sql_field = substr($field, 5);
            }
            if (strpos($field, 'plugin_') === 0) {
                continue;
            }
            $elements[] = $sql_field . "=" . $dbcon->qstr($udm->form->getSubmitValue($field));
        }
        $sql .= join(", ", $elements);
        $sql .= " WHERE id=" . $dbcon->qstr($udm->instance);
    } else {
        $sql = "INSERT INTO userdata_fields (";
        $frmFieldValues = $udm->form->exportValues(array_keys($udm->fields));
        $fields = array_keys($frmFieldValues);
        $values_noescape = array_values($frmFieldValues);
        foreach ($values_noescape as $value) {
            $values[] = $dbcon->qstr($value);
        }
        $fields[] = 'id';
        $values[] = lowerlimitInsertID('userdata_fields', 50);
        $sql .= join(", ", $fields);
        $sql .= ") VALUES ( ";
        $sql .= join(", ", $values);
        $sql .= " )";
    }
    $rs = $dbcon->Execute($sql) or die("There was an error completing the request: " . $dbcon->ErrorMsg());
    if ($rs) {
        $udmDef = new AMPSystem_UserData($dbcon);
        $udmDef->clearItemCache($udm->instance);
        // Run some default plugins. Plugins will not be run unless
        // they are pre-registered.
        //
        // These plugins should provide output to the user to reflect
        // their actions.
    } else {
        $udm->errorMessage("There was an error processing the request.");
    }
    return true;
}
Exemplo n.º 4
0
 function AMPSystemLookup_FormFields($form_id)
 {
     if (!$form_id) {
         return false;
     }
     require_once 'AMP/System/UserData.php';
     $form_def = new AMPSystem_UserData(AMP_Registry::getDbcon(), $form_id);
     $data = $form_def->getData();
     foreach ($data as $key => $value) {
         if (substr($key, 0, 8) == 'enabled_' && $value) {
             $short_key = substr($key, 8);
             $this->dataset[$short_key] = $data['label_' . $short_key];
         }
     }
 }
Exemplo n.º 5
0
 function _register_base()
 {
     /*
     $dbcon = &$this->dbcon;
     
     // Fetch database definition of module.
     $sql = "SELECT * FROM userdata_fields WHERE id=" . $dbcon->qstr( $this->instance );
     
     $rs = $dbcon->CacheExecute( $sql )
       or trigger_error( "Error retreiving module information from database: " . $dbcon->ErrorMsg() );
     
     $md = $this->_module_def = $rs->FetchRow();
     */
     $moduleSource = new AMPSystem_UserData($this->dbcon, $this->instance);
     if (!$moduleSource->hasData()) {
         return false;
     }
     $md = $this->_module_def = $moduleSource->getData();
     // Define module class
     $this->class = isset($md['class']) ? $md['class'] : 1;
     $this->modTemplateID = $md['modidinput'] or 10;
     // Define module variables.
     $this->name = $md['name'];
     // Define redirect config. Legacy, will be replaced by redirect plugin.
     $this->redirect = $md['redirect'];
     // Define email config. fixme, will be replaced by email plugins.
     if ($md['useemail'] == 1) {
         $this->mailto = $md['mailto'];
         $this->subject = $md['subject'];
     }
 }