public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $stored = false;
     $this->w2PTrimAll();
     // ensure changes of state in checkboxes is captured
     $this->project_active = (int) $this->project_active;
     $this->project_private = (int) $this->project_private;
     $this->project_target_budget = filterCurrency($this->project_target_budget);
     $this->project_actual_budget = filterCurrency($this->project_actual_budget);
     // Make sure project_short_name is the right size (issue for languages with encoded characters)
     $this->project_short_name = mb_substr($this->project_short_name, 0, 10);
     if (empty($this->project_end_date)) {
         $this->project_end_date = null;
     }
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->project_id = (int) $this->project_id;
     // convert dates to SQL format first
     if ($this->project_start_date) {
         $date = new w2p_Utilities_Date($this->project_start_date);
         $this->project_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_end_date) {
         $date = new w2p_Utilities_Date($this->project_end_date);
         $date->setTime(23, 59, 59);
         $this->project_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_actual_end_date) {
         $date = new w2p_Utilities_Date($this->project_actual_end_date);
         $this->project_actual_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     // check project parents and reset them to self if they do not exist
     if (!$this->project_parent) {
         $this->project_parent = $this->project_id;
         $this->project_original_parent = $this->project_id;
     } else {
         $parent_project = new CProject();
         $parent_project->load($this->project_parent);
         $this->project_original_parent = $parent_project->project_original_parent;
     }
     if (!$this->project_original_parent) {
         $this->project_original_parent = $this->project_id;
     }
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     $q = $this->_query;
     $this->project_updated = $q->dbfnNowWithTZ();
     if ($this->project_id && $perms->checkModuleItem('projects', 'edit', $this->project_id)) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->project_id && $perms->checkModuleItem('projects', 'add')) {
         $this->project_created = $q->dbfnNowWithTZ();
         if ($msg = parent::store()) {
             return $msg;
         }
         if (0 == $this->project_parent || 0 == $this->project_original_parent) {
             $this->project_parent = $this->project_id;
             $this->project_original_parent = $this->project_id;
             if ($msg = parent::store()) {
                 return $msg;
             }
         }
         $stored = true;
     }
     //split out related departments and store them seperatly.
     $q->setDelete('project_departments');
     $q->addWhere('project_id=' . (int) $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_departments) {
         foreach ($this->project_departments as $department) {
             if ($department) {
                 $q->addTable('project_departments');
                 $q->addInsert('project_id', $this->project_id);
                 $q->addInsert('department_id', $department);
                 $q->exec();
                 $q->clear();
             }
         }
     }
     //split out related contacts and store them seperatly.
     $q->setDelete('project_contacts');
     $q->addWhere('project_id=' . (int) $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_contacts) {
         foreach ($this->project_contacts as $contact) {
             if ($contact) {
                 $q->addTable('project_contacts');
                 $q->addInsert('project_id', $this->project_id);
                 $q->addInsert('contact_id', $contact);
                 $q->exec();
                 $q->clear();
             }
         }
     }
     if ($stored) {
         $custom_fields = new w2p_Core_CustomFields('projects', 'addedit', $this->project_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->project_id);
         // Store Custom Fields
         CTask::storeTokenTask($AppUI, $this->project_id);
     }
     return $stored;
 }
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $this->contact_company = (int) $this->contact_company;
     $this->contact_department = (int) $this->contact_department;
     $this->contact_owner = (int) $this->contact_owner;
     $this->contact_private = (int) $this->contact_private;
     $this->contact_first_name = $this->contact_first_name == null ? '' : $this->contact_first_name;
     $this->contact_last_name = $this->contact_last_name == null ? '' : $this->contact_last_name;
     $this->contact_order_by = $this->contact_order_by == null ? '' : $this->contact_order_by;
     $this->contact_display_name = $this->contact_display_name == null ? '' : $this->contact_display_name;
     $this->contact_birthday = $this->contact_birthday == '' ? null : $this->contact_birthday;
     /*
      *  This  validates that any Contact saved will have a Display Name as
      * required by various dropdowns, etc throughout the system.  This is
      * mostly required when Contacts are generated via programatic methods and
      * not through the add/edit UI.
      */
     if (mb_strlen($this->contact_order_by) <= 1) {
         $this->contact_order_by = mb_trim($this->contact_first_name . ' ' . $this->contact_last_name);
     }
     if (mb_strlen($this->contact_display_name) <= 1) {
         $this->contact_display_name = mb_trim($this->contact_first_name . ' ' . $this->contact_last_name);
     }
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $q = $this->_query;
     $this->contact_lastupdate = $q->dbfnNowWithTZ();
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     if ($this->contact_id) {
         // && $perms->checkModuleItem('contacts', 'edit', $this->contact_id)) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->contact_id) {
         // && $perms->checkModuleItem('contacts', 'add')) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if ($stored) {
         $custom_fields = new w2p_Core_CustomFields('contacts', 'addedit', $this->contact_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->contact_id);
         // Store Custom Fields
     }
     if ($stored) {
         $foto = W2P_BASE_DIR . '/fotos/' . $this->contact_id . '.jpg';
         $foto_temp = W2P_BASE_DIR . '/fotos/temp.jpg';
         if (file_exists($foto) && file_exists($foto_temp)) {
             unlink($foto);
         }
         if (file_exists($foto_temp)) {
             rename($foto_temp, $foto);
             if (file_exists($foto_temp)) {
                 unlink($foto_temp);
             }
         }
     }
     /*
      *  TODO: I don't like using the $_POST in here..
      */
     if ($stored) {
         $methods = array();
         if (!empty($_POST['contact_methods'])) {
             foreach ($_POST['contact_methods']['field'] as $key => $field) {
                 $methods[$field] = $_POST['contact_methods']['value'][$key];
             }
         }
         $this->setContactMethods($methods);
     }
     return $stored;
 }
 public function store(CAppUI $AppUI)
 {
     $perms = $AppUI->acl();
     $stored = false;
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->company_id = (int) $this->company_id;
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     if ($this->company_id && canEdit('companies', $this->company_id)) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->company_id && canAdd('companies')) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if ($stored) {
         $custom_fields = new w2p_Core_CustomFields('companies', 'addedit', $this->company_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->company_id);
         // Store Custom Fields
     }
     return $stored;
 }
 public function store(CAppUI $AppUI)
 {
     $perms = $AppUI->acl();
     $stored = false;
     if (!$this->event_recurs) {
         $this->event_times_recuring = 0;
     } else {
         //If the event recurs then set the end date day to be equal to the start date day and keep the hour:minute of the end date
         //so that the event starts recurring from the start day onwards n times after the start date for the period given
         //Meaning: The event end date day is useless as far as recurring events are concerned.
         $start_date = new w2p_Utilities_Date($this->event_start_date);
         $end_date = new w2p_Utilities_Date($this->event_end_date);
         $hour = $end_date->getHour();
         $minute = $end_date->getMinute();
         $end_date->setDate($start_date->getDate());
         $end_date->setHour($hour);
         $end_date->setMinute($minute);
         $this->event_end_date = $end_date->format(FMT_DATETIME_MYSQL);
     }
     // ensure changes to check boxes and select lists are honoured
     $this->event_private = (int) $this->event_private;
     $this->event_type = (int) $this->event_type;
     $this->event_cwd = (int) $this->event_cwd;
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->event_start_date = $AppUI->convertToSystemTZ($this->event_start_date);
     $this->event_end_date = $AppUI->convertToSystemTZ($this->event_end_date);
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     if ($this->event_id && $perms->checkModuleItem('events', 'edit', $this->event_id)) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->event_id && $perms->checkModuleItem('events', 'add')) {
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if ($stored) {
         // TODO:  I *really* don't like using the POST inside here..
         $this->updateAssigned(explode(',', $_POST['event_assigned']));
         $custom_fields = new w2p_Core_CustomFields('calendar', 'addedit', $this->event_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->event_id);
         // Store Custom Fields
     }
     return $stored;
 }
示例#5
0
require_once W2P_BASE_DIR . '/classes/ui.class.php';
$AppUI = new w2p_Core_CAppUI();
$updatekey = w2PgetParam($_POST, 'updatekey', 0);
$contact_id = (int) CContact::getContactByUpdatekey($updatekey);
if (!$contact_id) {
    echo $AppUI->_('You are not authorized to use this page. If you should be authorized please contact the sender to give you another valid link, thank you.');
    exit;
}
$contact = new CContact();
if (!$contact->bind($_POST)) {
    $msg = $AppUI->_('There was an error recording your contact data, please contact the system administrator. Thank you very much.');
} else {
    $result = $contact->store();
    if (is_array($result)) {
        $msg = $AppUI->_('There was an error recording your contact data, please contact the system administrator. Thank you very much.');
    } else {
        $custom_fields = new w2p_Core_CustomFields('contacts', 'addedit', $contact->contact_id, 'edit', 1);
        $custom_fields->bind($_POST);
        $custom_fields->store($contact->contact_id);
        $contact->clearUpdateKey();
        $msg = $AppUI->_('Your contact data has been recorded successfully. Your may now close your browser window.  Thank you very much, ' . $contact->contact_first_name);
    }
}
?>
<html>
	<body>
		<?php 
echo $msg;
?>
	</body>
</html>
 protected function hook_postStore()
 {
     // TODO:  I *really* don't like using the POST inside here..
     $this->updateAssigned(explode(',', $_POST['event_assigned']));
     $custom_fields = new w2p_Core_CustomFields('calendar', 'addedit', $this->event_id, 'edit');
     $custom_fields->bind($_POST);
     $custom_fields->store($this->event_id);
     // Store Custom Fields
     parent::hook_postStore();
 }
 /**
  * This method is called within $this->store() but only after the object
  *   was stored properly. You might use this to send notifications or
  *   update other objects.
  * @todo TODO: I REALLY hate this $_POST here.. it's just asking for trouble.
  *
  * @return \w2p_Core_BaseObject
  */
 protected function hook_postStore()
 {
     $custom_fields = new w2p_Core_CustomFields($this->_tbl_module, 'addedit', $this->{$this->_tbl_key}, 'edit');
     $custom_fields->bind($_POST);
     $custom_fields->store($this->{$this->_tbl_key});
     $prefix = $this->_getColumnPrefixFromTableName($this->_tbl);
     $name = '' != $this->{$prefix . '_name'} ? $this->{$prefix . '_name'} : '';
     addHistory($this->_tbl, $this->{$this->_tbl_key}, $this->_event, $name . ' - ' . $this->_AppUI->_('ACTION') . ': ' . $this->_event . ' ' . $this->_AppUI->_('TABLE') . ': ' . $this->_tbl . ' ' . $this->_AppUI->_('ID') . ': ' . $this->{$this->_tbl_key});
     return $this;
 }