/**
  * Validate the email field for contact forms.
  * @param I2CE_FormField $formfield
  */
 public function validate_form_user_request_field_email($formfield)
 {
     $value = $formfield->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $formfield->setInvalidMessage("invalid_email");
     }
 }
 /**
  * Validate the email field for contact forms.
  * @param I2CE_FormField $formfield
  */
 public function validate_form_contact_field_email($formfield)
 {
     $value = $formfield->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $formfield->setInvalidMessage('invalid_email');
     }
 }
 /**
  * Create a new instance of a I2CE_FormField
  * @param string $name
  * @param array $options A list of options for this form field.
  */
 public function __construct($name, $options)
 {
     parent::__construct($name, $options);
     $this->use_date_picker = I2CE_ModuleFactory::instance()->isEnabled('DatePicker');
     $this->start_year = 0;
     $this->end_year = 0;
 }
 /**
  * update value of each  instance  of a given form field by a sql  function call
  * @param I2CE_FormField $form_field
  * @param array $where Array of where data
  * @param string $set_sql sql used to update the field
  */
 public function globalFieldUpdateBySQL($form_field, $where, $set_sql)
 {
     if (!$form_field instanceof I2CE_FormField) {
         I2CE::raiseError("Not passed form_field");
         return false;
     }
     $formObj = $form_field->getContainer();
     if (!$formObj instanceof I2CE_Form) {
         I2CE::raiseError("No form as a container for the form field");
         return false;
     }
     $form = $formObj->getName();
     if (!$set_sql) {
         I2CE::raiseError("No SQL provided to update {$form}+{$field}");
         return false;
     }
     $sub_qry = $this->getRequiredFieldsQuery($form, array($form_field->getName()));
     $where_qry = $formObj->generateWhereClause($where);
     if (!$where_qry) {
         I2CE::raiseError("Could not gernerate where clasue for {$form} by\n" . print_r($where, true));
         return false;
     }
     $qry = "UPDATE config_alt JOIN ({$sub_qry}) AS data  " . "ON  parent = CONCAT( '/I2CE/formsData/forms/{$form}/', `{$form}+id` , '/fields' ) " . "SET value = {$set_sql} " . " WHERE (name = '" . $form_field->getName() . "' AND ({$where_qry}))";
     //I2CE::raiseError("Updating by $qry");
     $res = $this->db->exec($qry);
     I2CE::getConfig()->clearCache(false);
     //since we did a write to the DB, need to clear cache
     if (I2CE::pearError("Cannot update by:\n{$qry}", $res)) {
         return false;
     }
     return true;
 }
 /**
  * Generates a limit expression for a field based on  limit data
  * @param I2CE_FormField $fieldObj
  * @param mixed $limit_data
  * @param callback $ref.  A callback function whose first arguement is the form, the second arguements
  * is the field and which returns the way the field value should be references as a field.  If the callback is null (the default) then
  * the reference used is "$form+$field"
  * @param string $parent_ref.  Defaults to null.  If not null, it is the referent to the parent id of the form
  * @returns string SQL statement false on failure
  */
 public function generateFieldLimit($fieldObj, $limit_data, $ref, $parent_ref = null)
 {
     if (!is_array($limit_data)) {
         I2CE::raiseError("Expected array for generating field limit, but not received");
         return false;
     }
     if (!array_key_exists('style', $limit_data) || !is_string($limit_data['style'])) {
         I2CE::raiseError("Style is not given at 'style' ");
         return false;
     }
     if (!array_key_exists('data', $limit_data) || !is_array($limit_data['data'])) {
         $limit_data['data'] = array();
     }
     $method = 'generateLimit_' . $limit_data['style'];
     if (!$fieldObj->_hasMethod($method)) {
         I2CE::raiseError("Not able to generate limit for style  " . $limit_data['style'] . " by method ({$method}) for class " . get_class($fieldObj));
         return false;
     }
     $ret = $fieldObj->{$method}($limit_data['data'], $ref, $parent_ref);
     if (is_string($ret)) {
         return $ret;
     } else {
         I2CE::raiseError("Unexpected return from limit {$style}:" . print_r($ret, true));
         return false;
     }
 }
 /**
  * Get/prepare the prepared statement for the given field obj
  * @param I2CE_FormField $fieldObj
  * @returns mixed.  false om failure.  a mdb2 preapred statement object on success
  */
 protected function getFieldSave($fieldObj)
 {
     $formName = $fieldObj->getContainer()->getName();
     $fieldName = $fieldObj->getName();
     if (!array_key_exists($formName, $this->fieldSaves)) {
         $this->fieldSaves[$formName] = array();
     }
     if (!array_key_exists($fieldName, $this->fieldSaves[$formName])) {
         $cols = $this->getSaveColumns($fieldObj->getContainer());
         $table = $this->getTable($formName);
         if (!$table || !array_key_exists($fieldName, $cols)) {
             $this->fieldSaves[$formName][$fieldName] = false;
             return false;
         }
         $stmt = "UPDATE {$table} SET `{$cols[$fieldName]}` = ? WHERE `{$cols['id']}` = ?";
         $prepStmt = $this->db->prepare($stmt, array($fieldObj->getMDB2Type(), 'text'), MDB2_PREPARE_MANIP);
         if (I2CE::pearError($prepStmt, "Error preparing save statemnt for " . $fieldObj->getName() . "\n" . $stmt)) {
             $prepStmt = false;
         }
         $this->fieldSaves[$formName][$fieldName] = $prepStmt;
     }
     return $this->fieldSaves[$formName][$fieldName];
 }
Ejemplo n.º 7
0
 /**
  * Shows details the underlying database information and class information of a  form field.
  * Intend to be called when there is no form instance we are going to set (i.e. no id for a record is
  * expected to be give)
  * @param string $form
  * @param I2CE_MagicDataNode $fieldConfig.  The magic data node /modules/forms/formClasses/$form/fields/$fieldName
  * where $fieldName is the name of the field we are adding
  * @param boolean $even (Defaults to false). If true, will add the class 'even' to the created form field nodes.
  */
 protected function showFieldDetails($detailNode, $form, $fieldConfig, $even = 'I2CE_FormField')
 {
     $field = $fieldConfig->getName();
     die("deprecated bbaddness in i2ceformbrowser");
     $details = I2CE_FormField::getFormFieldIdAndType($form, $field);
     $fieldNode = $this->template->appendFileById("formBrowser_form_details_no_record.html", "tr", "particular_record", false, $detailNode);
     if (!$fieldNode instanceof DOMNode) {
         return;
     }
     if ($even) {
         $fieldNode->setAttribute('class', 'even');
     }
     $fieldType = "";
     $fieldClass = "";
     $fieldConfig->setIfIsSet($fieldType, "formfield");
     I2CE::getConfig()->setIfIsSet($fieldClass, "/modules/forms/FORMFIELD/{$fieldType}");
     $this->template->setDisplayDataImmediate('field_class', $fieldClass, $fieldNode);
     $this->template->setDisplayDataImmediate('field_type', $fieldType, $fieldNode);
     $this->template->setDisplayDataImmediate('field_name', $field, $fieldNode);
     $this->template->setDisplayDataImmediate('field_id', $details['id'], $fieldNode);
 }
 /**
  * Return the list of scheduled course for the given course id.
  * @param integer $course_id.  Defaults to zero meaning we get all courses
  * @param boolean $flat.  defaults to false
  * @return array the keys are the id of the scheduled course, the values are the string "$start_date -- $end_date"
  */
 public static function getScheduledCourses($course_id = 0, $flat = false)
 {
     if ($course_id > 0) {
         $flat = true;
     }
     $values = array();
     foreach (array('start_date', 'end_date') as $field) {
         $data = I2CE_FormField::getFormFieldIdAndType('scheduled_training_course', $field);
         if (!is_array($data)) {
             I2CE::raiseError("Could not available courses b/c could not find field {$field} in form scheduled_training_course");
             return array();
         }
         $values[] = $data['id'];
     }
     $query = "SELECT le_start_date.record AS id, le_start_date.date_value AS start_date, le_end_date.date_value AS end_date,  r.parent AS parent ";
     $query .= "FROM last_entry le_start_date ";
     $query .= "JOIN last_entry le_end_date ON le_start_date.record = le_end_date.record ";
     $query .= "JOIN record r ON le_start_date.record = r.id ";
     $query .= "WHERE le_start_date.form_field = ? ";
     $query .= "AND le_end_date.form_field = ? ";
     if ($course_id > 0) {
         $query .= "AND r.parent = ? ";
         $values[] = $course_id;
     }
     $query .= "ORDER BY le_start_date.date_value DESC, le_end_date.date_value ASC";
     $db = MDB2::singleton();
     $sth = $db->prepare($query, array('integer', 'integer'), MDB2_PREPARE_RESULT);
     if (I2CE::pearError($sth, "Could not setup statement to get available courses")) {
         return array();
     }
     $results = $sth->execute($values);
     if (I2CE::pearError($results, "Could not get available courses")) {
         return array();
     }
     $scheduled_courses = array();
     while ($result =& $results->fetchRow()) {
         $start_date = I2CE_Date::fromDB($result->start_date);
         $end_date = I2CE_Date::fromDB($result->end_date);
         if ($flat) {
             $scheduled_courses[$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate();
         } else {
             $scheduled_courses[$result->parent][$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate();
         }
     }
     return $scheduled_courses;
 }
 /**  
  * Check to see if the given DB value is equivalent to this value.
  * @param mixed $db_value Either a DB Value or an I2CE_FormField
  * @return boolean
  */
 public function isSameValue($db_value)
 {
     return parent::isSameValue($db_value) && $this->compare($db_value) == 0;
 }
 /**
  *Get the array of function details at the specified for the specified function at the speci
  * @var I2CE_MagicDataNode $funcConfig
  * @var array $dependents  A list of functions this function depends on
  */
 protected function _getFunctionDetails($funcConfig, $dependents)
 {
     if (!$funcConfig instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Bad function config");
         return false;
     }
     $qry = '';
     if (!$funcConfig->setIfIsSet($qry, 'qry')) {
         I2CE::raiseError("Function {$function} is not defined");
         return false;
     }
     $qry = trim($qry);
     if (!$qry) {
         //no query set so skip it
         I2CE::raiseError("Function {$function} is empty");
         return false;
     }
     $function = $funcConfig->getName();
     if (!$funcConfig->setIfIsSet($formfield, 'formfield') || !($fieldObj = I2CE_FormField::createField($funcConfig->formfield, $function)) instanceof I2CE_FormField) {
         I2CE::raiseError("Function {$function} cannot be associated to a form field:\n" . print_r($funcConfig->getAsArray(), true));
         return false;
     }
     preg_match_all('/`([a-zA-Z0-9\\_\\-]+\\+[a-zA-Z0-9\\_\\-]+)`/', $qry, $required_fields);
     $aggregate = false;
     $funcConfig->setIfIsSet($aggregate, 'aggregate');
     return array('qry' => $qry, 'type' => $fieldObj->getDBType(), 'required_fields' => array_unique($required_fields[1]), 'field' => $fieldObj, 'aggregate' => $aggregate, 'dependents' => $dependents);
 }
 /**
  * update value of each  instance  of a given form field by a sql  function call
  * @param I2CE_FormField $form_field
  * @param array $where Array of where data
  * @param string $set_sql sql used to update the field
  */
 public function globalFieldUpdateBySQL($form_field, $where, $set_sql)
 {
     if (!$form_field instanceof I2CE_FormField) {
         I2CE::raiseError("Not passed form_field");
         return false;
     }
     $formObj = $form_field->getContainer();
     if (!$formObj instanceof I2CE_Form) {
         I2CE::raiseError("No form as a container for the form field");
         return false;
     }
     $form = $formObj->getName();
     if (!$set_sql) {
         I2CE::raiseError("No SQL provided to update {$form}+{$field}");
         return false;
     }
     $where_qry = $formObj->generateWhereClause($where);
     if (!$where_qry) {
         I2CE::raiseError("Could not gernerate where clasue for {$form} by\n" . print_r($where, true));
         return false;
     }
     $this->setupForm($formObj);
     $referenceCallback = $this->generateReferenceCallback_2($form, $form_field->getName());
     if (!$referenceCallback) {
         return false;
     }
     if ($form_field->getName() == 'parent') {
         $formID = $this->getFormId($form, true);
         if (!$formID) {
             //form has not been saved to yet
             return false;
         }
         $last_entry_fields_qry = $this->_getRequiredFieldsQuery($form, array($form_field->getName()), null, false, null, -1, true);
         if (!$last_entry_fields_qry) {
             I2CE::raiseError("Could not generage field query for " . $form_field->getName());
             return false;
         }
         $qry = "UPDATE record JOIN ({$last_entry_fields_qry} ) AS data ON record.id = data.`{$form}+id` SET  " . "record.parent_form = SUBSTR({$set_sql},1,LOCATE('|',{$set_sql})-1)," . "record.parent_id = CONVERT(SUBSTR({$set_sql},LOCATE('|',{$set_sql})+1),SIGNED INTEGER) WHERE ( (record.form = {$formID}  )AND ({$where_qry}))";
         //I2CE::raiseError("Updating by $qry");
         $res = $this->db->exec($qry);
         if (I2CE::pearError("Cannot update by:\n{$qry}", $res)) {
             return false;
         }
     } else {
         $last_entry_fields_qry = $this->_getRequiredFieldsQuery($form, array($form_field->getName()), null, false, null, -1, true);
         $entry_fields_qry = $this->_getRequiredFieldsQuery($form, array($form_field->getName()), null, false, null, -1, false);
         if (!$last_entry_fields_qry) {
             I2CE::raiseError("Could not generage field query for " . $form_field->getName());
             return false;
         }
         if (!$entry_fields_qry) {
             I2CE::raiseError("Could not generage field query for " . $form_field->getName());
             return false;
         }
         $details = $this->getFormFieldIdAndType($form, $form_field->getName());
         if (!is_array($details) || !array_key_exists('type', $details)) {
             // This shoueld be rare but could happen if no data has been saved yet.  Interpret as nothing to update
             return true;
         }
         $qry = "UPDATE last_entry JOIN ({$last_entry_fields_qry} ) AS data ON last_entry.record = data.`{$form}+id` SET  " . 'last_entry.`' . $details['type'] . '_value`  = ' . $set_sql . ' WHERE (last_entry.form_field = ' . $details['id'] . " AND ({$where_qry}))";
         //I2CE::raiseError("Updating by $qry");
         $res = $this->db->exec($qry);
         if (I2CE::pearError("Cannot update by:\n{$qry}", $res)) {
             return false;
         }
         $qry = "UPDATE entry  JOIN ({$entry_fields_qry} ) AS data ON entry.record = data.`{$form}+id` SET  " . 'entry.`' . $details['type'] . '_value`  = ' . $set_sql . ' WHERE (entry.form_field = ' . $details['id'] . " AND ({$where_qry}) )";
         //I2CE::raiseError("Updating by $qry");
         $res = $this->db->exec($qry);
         if (I2CE::pearError("Cannot update by:\n{$qry}", $res)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 /**
  * Hooked Function to check if a field is unique
  * @param I2CE_FormField $field_obj
  */
 public function validate_formfield($field_obj)
 {
     if (!$field_obj->hasOption('unique') || !$field_obj->getOption('unique') || !$field_obj->isValid()) {
         return;
     }
     if (!$field_obj->hasOption('unique_field')) {
         return;
     }
     $unique = $field_obj->getOption('unique_field');
     if (strpos($unique, ':') === false) {
         //the value is not a mapped thing.  this is handled by hooked mehtod defined in I2CE_FormStorage
         return;
     }
     $form_obj = $field_obj->getContainer();
     if (!$form_obj instanceof I2CE_Form) {
         return;
     }
     $factory = I2CE_FormFactory::instance();
     //$unique should have the form 'unqique_field:form2(+field2):..:..:formM(+fieldM):...:formN
     //example $unique = 'region:country' or 'region+region+country:country' are the same.
     //    means that $field_obj needs to be unqiue when reseticted to the set of forms within a country and all of its regions
     //    the country and the region that is specified is the
     //    in this case, we need that region is a field of $form_obj
     //example: $unqiue = 'county:district+region:region:country' or 'county:district:region:country' are the same
     //    means that $field_obj needs to be unique when resitrcicted to a country, any of its regions any of those regions
     //    in this case, we need that county is a field of $form_obj
     //example: $unqiue = '[location]county:district+region:region:country' or 'county:district:region:country' are the same
     //    means that $field_obj needs to be unique when resitrcicted to a country, any of its regions any of those regions
     //    in this case, we need that location is a field of $form_obj
     $unique_fields = explode(',', $unique);
     $matches = null;
     $names = array();
     $main_where = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue()));
     foreach ($unique_fields as $unique_field) {
         if ($matches === false) {
             break;
         }
         if (strpos($unique_field, ':') === false) {
             //this field is not mapped... just handle it as a regular value.
             if (!($unique_field_obj = $form_obj->getField($unique_field)) instanceof I2CE_FormField) {
                 I2CE::raiseError("Invalid field {$unqiue_field}");
                 return;
             }
             if ($unique_field_obj->hasHeader('default')) {
                 $names[] = $unique_field_obj->getHeader('default');
             } else {
                 $names[] = $unique_field_obj->getName();
             }
             $where = array($main_where);
             if ($unique_field_obj->getDBValue()->isValid()) {
                 $where[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue()));
             } else {
                 $where[] = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue())), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'null', 'field' => $unique_field_obj->getName())));
             }
             if (count($where) > 1) {
                 $where = array('operator' => 'AND', 'operand' => $where);
             }
             $found = I2CE_FormStorage::search($form_obj->getName(), false, $where);
             foreach ($found as &$f) {
                 $f = (string) $f;
             }
             $matches = count($found) > 0 && in_array((string) $form_obj->getId(), $found, true);
         } else {
             $field_path = explode(':', $unique_field);
             $restricted_field = false;
             if (preg_match('/^\\[(.*?)\\](.*)$/', $field_path[0])) {
                 $restricted_field = $matches[1];
                 $field_path[0] = $matches[2];
             } else {
                 if (preg_match('/^(.*?)\\+(.*)$/', $field_path[0], $matches)) {
                     $restricted_field = $matches[1];
                 } else {
                     $restricted_field = $field_path[0];
                 }
             }
             $restricted_field_obj = $form_obj->getField($restricted_field);
             if (!$restricted_field_obj instanceof I2CE_FormField_MAP) {
                 I2CE::raiseError("Invalid field passed as restricted field for " . $form_obj->getName() . ": {$unique_field}");
                 return;
             }
             if ($restricted_field_obj->hasHeader('default')) {
                 $names[] = $restricted_field_obj->getHeader('default');
             } else {
                 $names[] = $restricted_field_obj->getName();
             }
             //now let's split up field_path into the forms and the fields
             $top_formid = I2CE_List::walkupFieldPath($field_path, $restricted_field_obj->getDBValue());
             if ($top_formid === false) {
                 //the value is not set. or inappropriately set.  error silently.
                 //this is handled by hooked method defined in I2CE_Module_Form.
                 return;
             }
             //now we get all forms under $top_formid defined by the field path
             $field_name = $field_obj->getName();
             $field_val = $field_obj->getDBValue();
             $form_id = $form_obj->getID();
             $dtree_path = $field_path;
             array_unshift($dtree_path, $form_obj->getName());
             list($top_form, $top_id) = explode('|', $top_formid, 2);
             $dtree_limits = array($top_form => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => 'id', 'data' => array('value' => $top_id)), $form_obj->getName() => $main_where);
             $options = I2CE_List::buildDataTree($dtree_path, array($form_obj->getName()), $dtree_limits);
             $options = I2CE_List::flattenDataTree($options);
             if (count($options) == 1) {
                 // If there's only one match and it is this form then don't block
                 // changes.
                 if ($options[0]['value'] != $form_obj->getNameId()) {
                     $matches = true;
                 }
             } elseif (count($options) > 1) {
                 $matches = true;
             }
             /*
             array_pop($field_path);
             $options = I2CE_List::monsterMash(
                 $form_obj->getName(),  //facility
                 $restricted_field, //location
                 $top_formid, //country|10
                 $field_path, //array(county+district,district+region,region+country)            
                 $field_name, //name
                 false
                 );
             
             //starts get all facility where location = country|10  
             //    get all regions region|X where region+country = country|10
             //    this means we need to start with
             //           link_field = country (e.g link_field_path[$len-1] 
             //           list(sub_form,sub_link_field) = explode(+,end(subfields) ) == (region,country)
             //             
             //next get all facility where location = residence|X 
             $option_matches = false;
             foreach ($options as $id=>$data) {
                 if (array_key_exists($field_name,$data) && ($data[$field_name] == $field_val) && ( $id != $form_id)) {
                     $option_matches =true;
                     break;
                 }
             }
             $matches = ($option_matches);
             */
         }
     }
     if ($matches === true) {
         if (count($names) > 1) {
             $field_obj->setInvalidMessage('unique_fields', null, ' ' . implode(', ', $names));
         } else {
             if (count($names) == 1) {
                 $field_obj->setInvalidMessage('unique_field', null, ' ' . implode(', ', $names));
             } else {
                 $field_obj->setInvalidMessage('unique');
             }
         }
         return;
     }
 }
Ejemplo n.º 13
0
 protected function updatePersonFormFields()
 {
     ini_set('max_execution_time', 6000);
     ini_set('memory_limit', "64M");
     $db = MDB2::singleton();
     $factory = I2CE_FormFactory::instance();
     if ($db->supports('transactions')) {
         $db->beginTransaction();
     }
     $personFormId = I2CE_Form::getFormId("person", true);
     if ($personFormId == 0) {
         I2CE::raiseError("Unable to get person form id.  Assuming that no person forms have ever been created.");
         if ($db->in_transaction) {
             $db->rollback();
         }
         return true;
     }
     $adminUser = I2CE_User::findUser('role', 'admin', false);
     if (!$adminUser instanceof I2CE_User) {
         I2CE::raiseError("Cannot find an administrative user");
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     $details = array();
     $changes = array('country' => 'residence_country', 'district' => 'residence_district', 'county' => 'county_district');
     foreach (array_keys($changes) as $location) {
         die("deprecated badness in managemodule");
         $details[$location] = I2CE_FormField::getFormFieldIdAndType("person", $location);
         if ($details[$location] === null) {
             I2CE::raiseError("Unable to get details for person:{$location}.  Assuming that is has never beens used so skipping.");
             if ($db->in_transaction) {
                 $db->rollback();
             }
             unset($changes[$location]);
             continue;
         }
         $details[$location]['qry'] = $db->prepare("SELECT " . $details[$location]['type'] . "_value as val FROM last_entry where record = ? and form_field = ? LIMIT 1", array("integer", "integer"), MDB2_PREPARE_RESULT);
         if (I2CE::pearError($details[$location]['qry'], "Error preping statement:")) {
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
     }
     $qry = $db->prepare('SELECT id from record where form = ?', array('integer'), MDB2_PREPARE_RESULT);
     if (I2CE::pearError($qry, "Error preping select records")) {
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     $results = $qry->execute($personFormId);
     if (I2CE::pearError($results, "Error getting records")) {
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     while ($row = $results->fetchRow()) {
         $person = $factory->createContainer('person' . '|' . $row->id);
         if (!$person instanceof iHRIS_Person) {
             I2CE::raiseError("Unable to create person with id " . $row->id);
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
         $person->populate();
         foreach ($changes as $old => $new) {
             $t_results = $details[$old]['qry']->execute(array($row->id, $details[$old]['id']));
             if (I2CE::pearError($t_results, "Error selecting data for {$old} for id " . $row->id)) {
                 if ($db->in_transaction) {
                     $db->rollback();
                 }
                 return false;
             }
             $t_row = $t_results->fetchRow();
             if (!$t_row) {
                 continue;
                 //we did not get anything
             }
             if (I2CE::pearError($t_row, "Error getting data for {$old} for id " . $row->id)) {
                 if ($db->in_transaction) {
                     $db->rollback();
                 }
                 return false;
             }
             $person->{$new} = $t_row->val;
         }
         if (!$person->save($adminUser)) {
             I2CE::raiseError("Unable to save record " . $row->id);
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
         $person->cleanup();
     }
     if ($db->in_transaction) {
         return $db->commit() == MDB2_OK;
     } else {
         return true;
     }
 }
 /**
  * Displays any report limits in the content node
  * @param DOMNode $contentNode
  */
 protected function _displayReportFormLimit($reportform, $field, $limit, $contentNode, $rv_config, $reportConfig, $limitValues, $excludes, $merge = '')
 {
     $report = $reportConfig->getName();
     $reportformfield = "{$merge}{$reportform}+{$field}";
     $reportformfieldlimit = $reportformfield . "+" . $limit;
     if (in_array($reportformfieldlimit, $this->displayed_limits) || in_array($limit, $excludes)) {
         return;
     }
     $this->displayed_limits[] = $reportformfieldlimit;
     list($formObj, $fieldObj) = $this->getFormFieldObjects("{$reportform}+{$field}", $report);
     if (!$formObj instanceof I2CE_Form || !$fieldObj instanceof I2CE_FormField || !($limitConfig = $reportConfig->traverse("reporting_forms/{$reportform}/fields/{$field}/limits/{$limit}")) instanceof I2CE_MagicDataNode || !isset($limitConfig->enabled) || !$limitConfig->enabled) {
         return;
     }
     if ($field == 'id' && $formObj instanceof I2CE_List && ($fieldConfig = $reportConfig->traverse("reporting_forms/{$reportform}/fields/{$field}")) instanceof I2CE_MagicDataNode && isset($fieldConfig->form_display) && $fieldConfig->form_display) {
         $idFieldConf = array('meta' => array('form' => array($formObj->getName())));
         if (isset($fieldConfig->form_display_fields) && $fieldConfig->form_display_fields) {
             $idFieldConf['meta']['display'] = array('default' => array('fields' => $fieldConfig->form_display_fields));
         }
         $fieldObj = I2CE_FormField::createField("MAP", "id", $idFieldConf);
     }
     if (array_key_exists($reportformfield, $limitValues)) {
         $fieldLimitValues = $limitValues[$reportformfield];
     } else {
         $fieldLimitValues = array();
     }
     if (array_key_exists($limit, $fieldLimitValues) && is_array($fieldLimitValues[$limit])) {
         $limitLimitValues = $fieldLimitValues[$limit];
     } else {
         $limitLimitValues = array();
     }
     //now we should have a valid limit
     $limit_default = 'default';
     $reportConfig->setIfIsSet($limit_default, "reporting_forms/{$reportform}/fields/{$field}/limit_default");
     $method = 'processLimitMenu_' . $limit;
     $data = $fieldObj->{$method}($limitLimitValues, false);
     $method = 'getLimitMenu_' . $limit;
     $node = $fieldObj->{$method}($this->template, "limits:{$merge}{$reportformfield}:{$limit}", $data, $limit_default);
     if (!$node instanceof DOMNode) {
         return;
     }
     $limitDesc = $fieldObj->describeLimit($limit, $data);
     if ($limitDesc && $limitDesc != "") {
         if ($limitConfig->is_scalar('header')) {
             $limitDescHeader = $limitConfig->header;
         } else {
             $limitDescHeader = $limitConfig->getName();
         }
         $this->limitDescText[] = $limitDescHeader . ": " . $limitDesc;
     }
     $this->displayReportLimit($contentNode, $node, $limitConfig);
 }
 /**
  * Save the FormField to the database.
  * @param I2CE_FormField $form_field
  * @param  boolean $do_check : A flag to determine if a check should be made for the same value being saved.
  * @param  I2CE_User $user: The user saving this data.
  * @return boolean
  */
 public function FF_save($form_field, $do_check, $user)
 {
     if (!$form_field->isInDB()) {
         return true;
     }
     if ($form_field->getDBValue() != "" && !$form_field->isValid()) {
         return true;
     }
     $form_config = $this->getFormConfig($form_field, true);
     if (!$form_config instanceof I2CE_MagicDataNode) {
         return false;
     }
     $fields_config = $form_config->fields;
     if (!$fields_config instanceof I2CE_MagicDataNode) {
         return false;
     }
     $field_name = $form_field->getName();
     if (!is_string($field_name) || strlen($field_name) == 0) {
         return false;
     }
     $fields_config->{$field_name} = $form_field->getDBValue();
     return true;
 }
 /**
  * Create a new instance of a I2CE_FormField
  * @param string $name
  * @param array $options A list of options for this form field.
  */
 public function __construct($name, $options)
 {
     parent::__construct($name, $options);
 }
Ejemplo n.º 17
0
 /**
  * Populate the history of entries for the form field if the storage module handles history.
  * @param I2CE_FormField $form_field
  * @return boolean
  */
 public function FF_populateHistory($form_field)
 {
     if ($form_field instanceof I2CE_FormField_STRING_PASS) {
         return false;
     }
     if ($form_field->hasAttribute('populated_history') && $form_field->getAttribute('populated_history')) {
         return true;
     }
     $storageMechanism = self::getStorageMechanism($form_field->getContainer()->getName());
     if (!$storageMechanism) {
         return false;
     }
     $form_field->setAttribute('populated_history', 1);
     return $storageMechanism->FF_populateHistory($form_field);
 }
Ejemplo n.º 18
0
 /**
  * Populate the history of entries for the form field if the storage module handles history.
  * @param I2CE_FormField $form_field
  * @return boolean
  */
 public function FF_populateHistory($form_field)
 {
     $field = $form_field->getName();
     $form = $form_field->getContainer();
     if (!$form instanceof I2CE_Form) {
         return false;
     }
     $fieldQry = $this->getRequiredFieldsQuery($form->getName(), array($field), $form->getId());
     $result = $this->db->getRow($fieldQry);
     if (I2CE::pearError($result, "Error populating field {$field} of form " . $form->getName())) {
         return false;
     }
     $ref = strtolower($form->getName() . '+' . $field);
     $entry = new I2CE_Entry(I2CE_Date::blank(), 1, 0, $form_field->getFromDB($result->{$ref}));
     $form_field->addHistory($entry);
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Adds a field to this form.
  * @param string $name 
  * @param array $args The arguments for this field
  * @returns mixed I2CE_FormField or false on failure
  */
 public function addField($name, $args)
 {
     if (!array_key_exists('formfield', $args) || !is_scalar($args['formfield'])) {
         I2CE::raiseError("No formfield passed to addField in container {$this->name} with field {$name}\n" . print_r($args, true), E_USER_WARNING);
         return false;
     }
     $this->preProcessFieldArgs($name, $args);
     $field = I2CE_FormField::createField($args['formfield'], $name, $args);
     if (!$field instanceof I2CE_FormField) {
         I2CE::raiseError("Could not create field {$name} in {$this->name} in container {$this->name}");
         return false;
     }
     $name = $field->getName();
     if (!$name || $name == "") {
         I2CE::raiseError("Invalid field name for I2CE_Form::addField.", E_USER_NOTICE);
         return false;
     }
     $field->setContainer($this);
     $this->fields[$name] = $field;
     return $field;
 }
 /**
  * Populate the history of entries for the form field if the storage module handles history.
  * @param I2CE_FormField $form_field
  * @return boolean
  */
 public function FF_populateHistory($form_field)
 {
     $field = $form_field->getName();
     $form = $form_field->getContainer();
     if (!$form instanceof I2CE_Form) {
         return false;
     }
     $field_name = $form_field->getName();
     $fields = $this->lookupField($form->getName(), $form->getId(), array($field_name), false);
     if (!is_array($fields) || !array_key_exists($field_name, $fields)) {
         //no data to populate
         return true;
     }
     $last_modified = I2CE_Date::blank();
     $entry = new I2CE_Entry($last_modified, 1, 0, $form_field->getFromDB($fields[$field_name]));
     $form_field->addHistory($entry);
     return true;
 }
Ejemplo n.º 21
0
 /**
  * Hooked Function to check if a fieldObj is valid
  * @param I2CE_FormField $fieldObj
  */
 public function validate_formfield($fieldObj)
 {
     if ($fieldObj->hasOption('required') && $fieldObj->getOption('required') && !$fieldObj->isValid()) {
         $fieldObj->setInvalidMessage("required");
     }
 }