Ejemplo n.º 1
0
 function store()
 {
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . "::store-check failed";
     }
     $q = new DBQuery();
     if ($this->user_id) {
         // save the old password
         $perm_func = "updateLogin";
         $q->addTable('users');
         $q->addQuery('user_password');
         $q->addWhere("user_id = {$this->user_id}");
         $pwd = $q->loadResult();
         if ($pwd != $this->user_password) {
             $this->user_password = md5($this->user_password);
             addHistory($this->_tbl, $this->user_id, 'password changed', 'Password changed from IP ' . $_SERVER['REMOTE_ADDR']);
         } else {
             $this->user_password = null;
         }
         $ret = db_updateObject('users', $this, 'user_id', false);
     } else {
         $perm_func = "addLogin";
         $this->user_password = md5($this->user_password);
         $ret = db_insertObject('users', $this, 'user_id');
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         $acl =& $GLOBALS['AppUI']->acl();
         $acl->{$perm_func}($this->user_id, $this->user_username);
         return NULL;
     }
 }
Ejemplo n.º 2
0
 function store()
 {
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . "::store-check failed";
     }
     $q = new DBQuery();
     if ($this->user_id) {
         // save the old password
         $perm_func = "updateLogin";
         $q->addTable('users');
         $q->addQuery('user_password');
         $q->addWhere("user_id = {$this->user_id}");
         $pwd = $q->loadResult();
         if ($pwd != $this->user_password) {
             $this->user_password = md5($this->user_password);
         } else {
             $this->user_password = null;
         }
         $ret = db_updateObject('users', $this, 'user_id', false);
     } else {
         $perm_func = "addLogin";
         $this->user_password = md5($this->user_password);
         $ret = db_insertObject('users', $this, 'user_id');
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         $acl =& $GLOBALS['AppUI']->acl();
         $acl->{$perm_func}($this->user_id, $this->user_username);
         //Insert Default Preferences
         //Lets check if the user has allready default users preferences set, if not insert the default ones
         $q->addTable('user_preferences', 'upr');
         $q->addWhere("upr.pref_user = {$this->user_id}");
         $uprefs = $q->loadList();
         $q->clear();
         if (!count($uprefs) && $this->user_id > 0) {
             //Lets get the default users preferences
             $q->addTable('user_preferences', 'dup');
             $q->addWhere("dup.pref_user = 0");
             $dprefs = $q->loadList();
             $q->clear();
             foreach ($dprefs as $dprefskey => $dprefsvalue) {
                 $q->addTable('user_preferences', 'up');
                 $q->addInsert('pref_user', $this->user_id);
                 $q->addInsert('pref_name', $dprefsvalue['pref_name']);
                 $q->addInsert('pref_value', $dprefsvalue['pref_value']);
                 $q->exec();
                 $q->clear();
             }
         }
         return NULL;
     }
 }
Ejemplo n.º 3
0
 function store()
 {
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . "::store-check failed - {$msg}";
     }
     if ($this->dept_id) {
         $ret = db_updateObject('departments', $this, 'dept_id', false);
     } else {
         $ret = db_insertObject('departments', $this, 'dept_id');
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }
Ejemplo n.º 4
0
 function store()
 {
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . "::store-check failed";
     }
     if ($this->risk_id) {
         $ret = db_updateObject('risks', $this, 'risk_id');
     } else {
         $ret = db_insertObject('risks', $this, 'risk_id');
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }
Ejemplo n.º 5
0
 /**
  * @todo Parent store could be partially used
  */
 function store()
 {
     global $AppUI;
     $q = new DBQuery();
     $this->dPTrimAll();
     $importing_tasks = false;
     $msg = $this->check();
     if ($msg) {
         $return_msg = array(get_class($this) . '::store-check', 'failed', '-');
         if (is_array($msg)) {
             return array_merge($return_msg, $msg);
         } else {
             array_push($return_msg, $msg);
             return $return_msg;
         }
     }
     if ($this->task_id) {
         addHistory('tasks', $this->task_id, 'update', $this->task_name, $this->task_project);
         $this->_action = 'updated';
         // Load and globalize the old, not yet updated task object
         // e.g. we need some info later to calculate the shifting time for depending tasks
         // see function update_dep_dates
         global $oTsk;
         $oTsk = new CTask();
         $oTsk->peek($this->task_id);
         // if task_status changed, then update subtasks
         if ($this->task_status != $oTsk->task_status) {
             $this->updateSubTasksStatus($this->task_status);
         }
         // Moving this task to another project?
         if ($this->task_project != $oTsk->task_project) {
             $this->updateSubTasksProject($this->task_project);
         }
         if ($this->task_dynamic == 1) {
             $this->updateDynamics(true);
         }
         // shiftDependentTasks needs this done first
         $this->check();
         $ret = db_updateObject('tasks', $this, 'task_id', false);
         // Milestone or task end date, or dynamic status has changed,
         // shift the dates of the tasks that depend on this task
         if ($this->task_end_date != $oTsk->task_end_date || $this->task_dynamic != $oTsk->task_dynamic || $this->task_milestone == '1') {
             $this->shiftDependentTasks();
         }
     } else {
         $this->_action = 'added';
         if ($this->task_start_date == '') {
             $this->task_start_date = '0000-00-00 00:00:00';
         }
         if ($this->task_end_date == '') {
             $this->task_end_date = '0000-00-00 00:00:00';
         }
         $ret = db_insertObject('tasks', $this, 'task_id');
         addHistory('tasks', $this->task_id, 'add', $this->task_name, $this->task_project);
         if (!$this->task_parent) {
             $q->addTable('tasks');
             $q->addUpdate('task_parent', $this->task_id);
             $q->addWhere('task_id = ' . $this->task_id);
             $q->exec();
             $q->clear();
         } else {
             // importing tasks do not update dynamics
             $importing_tasks = true;
         }
         // insert entry in user tasks
         $q->addTable('user_tasks');
         $q->addInsert('user_id', $AppUI->user_id);
         $q->addInsert('task_id', $this->task_id);
         $q->addInsert('user_type', '0');
         $q->exec();
         $q->clear();
     }
     //split out related departments and store them seperatly.
     $q->setDelete('task_departments');
     $q->addWhere('task_id=' . $this->task_id);
     $q->exec();
     $q->clear();
     // print_r($this->task_departments);
     if (!empty($this->task_departments)) {
         $departments = explode(',', $this->task_departments);
         foreach ($departments as $department) {
             $q->addTable('task_departments');
             $q->addInsert('task_id', $this->task_id);
             $q->addInsert('department_id', $department);
             $q->exec();
             $q->clear();
         }
     }
     //split out related contacts and store them seperatly.
     $q->setDelete('task_contacts');
     $q->addWhere('task_id=' . $this->task_id);
     $q->exec();
     $q->clear();
     if (!empty($this->task_contacts)) {
         $contacts = explode(',', $this->task_contacts);
         foreach ($contacts as $contact) {
             $q->addTable('task_contacts');
             $q->addInsert('task_id', $this->task_id);
             $q->addInsert('contact_id', $contact);
             $q->exec();
             $q->clear();
         }
     }
     // if is child update parent task
     if ($this->task_parent != $this->task_id) {
         if (!$importing_tasks) {
             $this->updateDynamics(true);
         }
         $pTask = new CTask();
         $pTask->load($this->task_parent);
         $pTask->updateDynamics();
         if ($oTsk->task_parent != $this->task_parent) {
             $old_parent = new CTask();
             $old_parent->load($oTsk->task_parent);
             $old_parent->updateDynamics();
         }
     }
     // update dependencies
     if (!empty($this->task_id)) {
         $this->updateDependencies($this->getDependencies());
     } else {
         // print_r($this);
     }
     if (!$ret) {
         return get_class($this) . '::store failed <br />' . db_error();
     } else {
         return NULL;
     }
 }
Ejemplo n.º 6
0
 function store()
 {
     $q = new DBQuery();
     $q->addQuery('billingcode_id');
     $q->addTable('billingcode');
     $q->addWhere("billingcode_name = '" . $this->billingcode_name . "'");
     $q->addWhere('company_id = ' . $this->company_id);
     $found_id = $q->loadResult();
     if ($found_id && $found_id != $this->_billingcode_id) {
         return 'Billing Code::code already exists';
     } else {
         if ($this->_billingcode_id) {
             $q->addTable('billingcode');
             $q->addUpdate('billingcode_desc', $this->billingcode_desc);
             $q->addUpdate('billingcode_name', $this->billingcode_name);
             $q->addUpdate('billingcode_value', $this->billingcode_value);
             $q->addUpdate('billingcode_status', $this->billingcode_status);
             $q->addUpdate('company_id', $this->company_id);
             $q->addWhere('billingcode_id = ' . $this->_billingcode_id);
             $q->exec();
             $q->clear();
         } else {
             if (!($ret = db_insertObject('billingcode', $this, 'billingcode_id'))) {
                 return 'Billing Code::store failed <br />' . db_error();
             } else {
                 return NULL;
             }
         }
     }
 }
Ejemplo n.º 7
0
 function store()
 {
     $this->dPTrimAll();
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . '::store-check failed - ' . $msg;
     }
     if ($this->project_id) {
         $ret = db_updateObject('projects', $this, 'project_id', false);
         addHistory('projects', $this->project_id, 'update', $this->project_name, $this->project_id);
     } else {
         $ret = db_insertObject('projects', $this, 'project_id');
         addHistory('projects', $this->project_id, 'add', $this->project_name, $this->project_id);
     }
     //split out related departments and store them seperatly.
     $q = new DBQuery();
     $q->setDelete('project_departments');
     $q->addWhere('project_id=' . $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_departments) {
         $departments = explode(',', $this->project_departments);
         foreach ($departments as $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=' . $this->project_id);
     $q->exec();
     $q->clear();
     if ($this->project_contacts) {
         $contacts = explode(',', $this->project_contacts);
         foreach ($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();
             }
         }
     }
     return !$ret ? get_class($this) . '::store failed <br />' . db_error() : NULL;
 }
Ejemplo n.º 8
0
 function createsqluser($username, $password, $ldap_attribs = array())
 {
     global $db, $AppUI;
     $hash_pass = MD5($password);
     require_once $AppUI->getModuleClass("contacts");
     if (!count($ldap_attribs) == 0) {
         // Contact information based on the inetOrgPerson class schema
         $c = new CContact();
         $c->contact_first_name = $ldap_attribs["givenname"][0];
         $c->contact_last_name = $ldap_attribs["sn"][0];
         $c->contact_email = $ldap_attribs["mail"][0];
         $c->contact_phone = $ldap_attribs["telephonenumber"][0];
         $c->contact_mobile = $ldap_attribs["mobile"][0];
         $c->contact_city = $ldap_attribs["l"][0];
         $c->contact_country = $ldap_attribs["country"][0];
         $c->contact_state = $ldap_attribs["st"][0];
         $c->contact_zip = $ldap_attribs["postalcode"][0];
         $c->contact_job = $ldap_attribs["title"][0];
         //print_r($c); die();
         db_insertObject('contacts', $c, 'contact_id');
     }
     $contact_id = $c->contact_id == NULL ? "NULL" : $c->contact_id;
     $q = new DBQuery();
     $q->addTable('users');
     $q->addInsert('user_username', $username);
     $q->addInsert('user_password', $hash_pass);
     $q->addInsert('user_type', '1');
     $q->addInsert('user_contact', $c->contact_id);
     $q->exec();
     $user_id = $db->Insert_ID();
     $this->user_id = $user_id;
     $q->clear();
     $acl =& $AppUI->acl();
     $acl->insertUserRole($acl->get_group_id('anon'), $this->user_id);
 }
Ejemplo n.º 9
0
 function store()
 {
     $msg = $this->check();
     if ($msg) {
         return "CForumMessage::store-check failed<br />{$msg}";
     }
     $q = new DBQuery();
     if ($this->message_id) {
         // First we need to remove any forum visits for this message
         // otherwise nobody will see that it has changed.
         $q->setDelete('forum_visits');
         $q->addWhere('visit_message = ' . $this->message_id);
         $q->exec();
         // No error if this fails, it is not important.
         $ret = db_updateObject('forum_messages', $this, 'message_id', false);
         // ! Don't update null values
         $q->clear();
     } else {
         $this->message_date = db_datetime(time());
         $new_id = db_insertObject('forum_messages', $this, 'message_id');
         ## TODO handle error now
         echo db_error();
         ## TODO handle error better
         $q->addTable('forum_messages');
         $q->addQuery('count(message_id), MAX(message_date)');
         $q->addWhere('message_forum = ' . $this->message_forum);
         $res = $q->exec();
         echo db_error();
         ## TODO handle error better
         $reply = db_fetch_row($res);
         $q->clear();
         //update forum descriptor
         $forum = new CForum();
         $forum->forum_id = $this->message_forum;
         $forum->forum_message_count = $reply[0];
         $forum->forum_last_date = $reply[1];
         $forum->forum_last_id = $this->message_id;
         $forum->store();
         ## TODO handle error now
         return $this->sendWatchMail(false);
     }
     if (!$ret) {
         return "CForumMessage::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }
Ejemplo n.º 10
0
 /**
  *	Inserts a new row if id is zero or updates an existing row in the database table
  *
  *	Can be overloaded/supplemented by the child class
  *	@return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     $this->dPTrimAll();
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . '::store-check failed<br />' . $msg;
     }
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         $store_type = 'update';
         $ret = db_updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         $store_type = 'add';
         $ret = db_insertObject($this->_tbl, $this, $this->_tbl_key);
     }
     if ($ret) {
         // only record history if an update or insert actually occurs.
         addHistory($this->_tbl, $this->{$k}, $store_type, $this->_tbl . '_' . $store_type . '(' . $this->{$k} . ')');
     }
     return !$ret ? get_class($this) . '::store failed <br />' . db_error() : NULL;
 }
Ejemplo n.º 11
0
 /**
  *	Inserts a new row if id is zero or updates an existing row in the database table
  *
  *	Can be overloaded/supplemented by the child class
  *	@return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     $this->dPTrimAll();
     $msg = $this->check();
     if ($msg) {
         return get_class($this) . "::store-check failed<br />{$msg}";
     }
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         addHistory($this->_tbl . '_update(' . $this->{$k} . ')', 0, $this->_tbl);
         $ret = db_updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         $ret = db_insertObject($this->_tbl, $this, $this->_tbl_key);
         addHistory($this->_tbl . '_add(' . $this->{$k} . ')', 0, $this->_tbl);
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }
Ejemplo n.º 12
0
 /**
 * @todo Parent store could be partially used
 */
 function store()
 {
     global $AppUI;
     $importing_tasks = false;
     $msg = $this->check();
     if ($msg) {
         $return_msg = array(get_class($this) . '::store-check', 'failed', '-');
         if (is_array($msg)) {
             return array_merge($return_msg, $msg);
         } else {
             array_push($return_msg, $msg);
             return $return_msg;
         }
     }
     if ($this->task_id) {
         addHistory('tasks', $this->task_id, 'update', $this->task_name, $this->task_project);
         $this->_action = 'updated';
         // Load the old task from disk
         $oTsk = new CTask();
         $oTsk->load($this->task_id);
         // if task_status changed, then update subtasks
         if ($this->task_status != $oTsk->task_status) {
             $this->updateSubTasksStatus($this->task_status);
         }
         // Moving this task to another project?
         if ($this->task_project != $oTsk->task_project) {
             $this->updateSubTasksProject($this->task_project);
         }
         if ($this->task_dynamic == '1') {
             $this->updateDynamics(true);
         }
         // shiftDependentTasks needs this done first
         $ret = db_updateObject('tasks', $this, 'task_id', false);
         // Milestone or task end date, or dynamic status has changed,
         // shift the dates of the tasks that depend on this task
         if ($this->task_end_date != $oTsk->task_end_date || $this->task_dynamic != $oTsk->task_dynamic || $this->task_milestone == '1') {
             $this->shiftDependentTasks();
         }
     } else {
         $this->_action = 'added';
         $ret = db_insertObject('tasks', $this, 'task_id');
         addHistory('tasks', $this->task_id, 'add', $this->task_name, $this->task_project);
         if (!$this->task_parent) {
             $sql = "UPDATE tasks SET task_parent = {$this->task_id} WHERE task_id = {$this->task_id}";
             db_exec($sql);
         } else {
             // importing tasks do not update dynamics
             $importing_tasks = true;
         }
         // insert entry in user tasks
         $sql = "INSERT INTO user_tasks (user_id, task_id, user_type) VALUES ({$AppUI->user_id}, {$this->task_id}, -1)";
         db_exec($sql);
     }
     //split out related departments and store them seperatly.
     $sql = 'DELETE FROM task_departments WHERE task_id=' . $this->task_id;
     db_exec($sql);
     // print_r($this->task_departments);
     if (!empty($this->task_departments)) {
         $departments = explode(',', $this->task_departments);
         foreach ($departments as $department) {
             $sql = 'INSERT INTO task_departments (task_id, department_id) values (' . $this->task_id . ', ' . $department . ')';
             db_exec($sql);
         }
     }
     //split out related contacts and store them seperatly.
     $sql = 'DELETE FROM task_contacts WHERE task_id=' . $this->task_id;
     db_exec($sql);
     if (!empty($this->task_contacts)) {
         $contacts = explode(',', $this->task_contacts);
         foreach ($contacts as $contact) {
             $sql = 'INSERT INTO task_contacts (task_id, contact_id) values (' . $this->task_id . ', ' . $contact . ')';
             db_exec($sql);
         }
     }
     if (!$importing_tasks && $this->task_parent != $this->task_id) {
         $this->updateDynamics();
     }
     // if is child update parent task
     if ($this->task_parent != $this->task_id) {
         $pTask = new CTask();
         $pTask->load($this->task_parent);
         $pTask->updateDynamics(true);
     }
     // update dependencies
     if (!empty($this->task_id)) {
         $this->updateDependencies($this->getDependencies());
     } else {
         print_r($this);
     }
     if (!$ret) {
         return get_class($this) . "::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }
 function store()
 {
     if (!($ret = db_insertObject('billingcode', $this, 'billingcode_id'))) {
         return "Billing Code::store failed <br />" . db_error();
     } else {
         return NULL;
     }
 }