예제 #1
0
    		JSON OUTPUT INITIALIZATION
    	 *********************************/
    Pommo::requireOnce($pommo->_baseDir . 'inc/classes/json.php');
    $json = new PommoJSON();
    SmartyValidate::connect($smarty);
    if (SmartyValidate::is_valid($_POST)) {
        // __ FORM IS VALID
        // TODO -> Which below logic is better? the computed diff, or send all fields for update?
        /*
        // make a difference between updated & original field
        $update = array_diff_assoc(PommoField::makeDB($_POST),$field);
        // restore the ID
        $update['id'] = $field['id'];
        */
        // let MySQL do the difference processing
        $update = PommoField::makeDB($_POST);
        if (!PommoField::update($update)) {
            $json->fail('error updating field');
        }
        $json->add('callbackFunction', 'updateField');
        $json->add('callbackParams', $update);
        $json->success(Pommo::_T('Settings updated.'));
    } else {
        // __ FORM NOT VALID
        $json->add('fieldErrors', $smarty->getInvalidFields());
        $json->fail(Pommo::_T('Please review and correct errors with your submission.'));
    }
}
$f_text = sprintf(Pommo::_T('%s - Any value will be accepted for text fields. They are useful for collecting names, addresses, etc.'), '<strong>' . $field['name'] . ' (' . Pommo::_T('Text') . ')</strong>');
$f_check = sprintf(Pommo::_T('%s - Checkboxes can be toggled ON or OFF. They are useful for opt-ins and agreements.'), '<strong>' . $field['name'] . ' (' . Pommo::_T('Checkbox') . ')</strong>');
$f_num = sprintf(Pommo::_T('%s - Only Numeric values will be accepted for number fields.'), '<strong>' . $field['name'] . ' (' . Pommo::_T('Number') . ')</strong>');
예제 #2
0
 function &get($p = array())
 {
     $defaults = array('active' => false, 'id' => null, 'byName' => true);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     $p['active'] = $p['active'] ? 'on' : null;
     $p['byName'] = $p['byName'] ? 'field_name' : 'field_ordering';
     $o = array();
     $query = "\n\t\t\tSELECT *\n\t\t\tFROM " . $dbo->table['fields'] . "\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND field_active='%S']\n\t\t\t\t[AND field_id IN(%C)]\n\t\t\tORDER BY " . $p['byName'];
     $query = $dbo->prepare($query, array($p['active'], $p['id']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['field_id']] = PommoField::makeDB($row);
     }
     return $o;
 }