public function deleteByObject($object_id)
 {
     $q = new w2p_Database_Query();
     $q->setDelete('custom_fields_values');
     $q->addWhere('value_object_id=' . (int) $object_id);
     $q->exec();
 }
 public function store($object_id)
 {
     global $db;
     $object_id = (int) $object_id;
     if ($object_id) {
         $this->value_intvalue = (int) $this->value_intvalue;
         $ins_charvalue = $this->value_charvalue == null ? '' : stripslashes($this->value_charvalue);
         $q = new w2p_Database_Query();
         $q->addTable('custom_fields_values');
         if ($this->value_id) {
             $q->addUpdate('value_charvalue', $ins_charvalue);
             $q->addUpdate('value_intvalue', $this->value_intvalue);
             $q->addWhere('value_id = ' . $this->value_id);
         } else {
             $q->addInsert('value_module', '');
             $q->addInsert('value_field_id', $this->field_id);
             $q->addInsert('value_object_id', $object_id);
             $q->addInsert('value_charvalue', $ins_charvalue);
             $q->addInsert('value_intvalue', $this->value_intvalue);
         }
         $rs = $q->exec();
         $q->clear();
         if (!$rs) {
             return $db->ErrorMsg() . ' | SQL: ';
         }
     } else {
         return 'Error: Cannot store field (' . $this->field_name . '), associated id not supplied.';
     }
 }
 public function delete()
 {
     $q = new w2p_Database_Query();
     $q->setDelete('custom_fields_lists');
     $q->addWhere('field_id = ' . (int) $this->field_id);
     $q->addWhere('list_option_id = ' . (int) $this->list_option_id);
     return $q->exec();
 }
Esempio n. 4
0
 public function remove(CAppUI $AppUI = null)
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     $q->dropTable('history');
     $q->exec();
     $perms = $AppUI->acl();
     return $perms->unregisterModule('history');
 }
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     $q->addTable('project_designer_options');
     $q->addReplace('pd_option_user', $this->pd_option_user);
     $q->addReplace('pd_option_view_project', $this->pd_option_view_project);
     $q->addReplace('pd_option_view_gantt', $this->pd_option_view_gantt);
     $q->addReplace('pd_option_view_tasks', $this->pd_option_view_tasks);
     $q->addReplace('pd_option_view_actions', $this->pd_option_view_actions);
     $q->addReplace('pd_option_view_addtasks', $this->pd_option_view_addtasks);
     $q->addReplace('pd_option_view_files', $this->pd_option_view_files);
     $q->addWhere('pd_option_user = ' . (int) $this->pd_option_user);
     $q->exec();
     return true;
 }
Esempio n. 6
0
 public function authenticate($username, $password)
 {
     global $db, $AppUI;
     $this->username = $username;
     $q = new w2p_Database_Query();
     $q->addTable('users');
     $q->addQuery('user_id, user_password');
     $q->addWhere("user_username = '******'");
     $q->addWhere("user_password = '******'");
     $q->exec();
     if ($row = $q->fetchRow()) {
         $this->user_id = $row['user_id'];
         return true;
     }
     return false;
 }
Esempio n. 7
0
 public function upgrade($old_version)
 {
     switch ($old_version) {
         case '1.0':
             $q = new w2p_Database_Query();
             $q->addTable('resources');
             $q->addField('resource_key', 'varchar(64) not null default ""');
             $q->exec();
             if (db_error()) {
                 return false;
             }
             // FALLTHROUGH
         // FALLTHROUGH
         case '1.0.1':
             break;
     }
     return true;
 }
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $stored = false;
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $q = new w2p_Database_Query();
     if ($this->message_id && $perms->checkModuleItem('forums', 'edit', $this->forum_id)) {
         $q->setDelete('forum_visits');
         $q->addWhere('visit_message = ' . (int) $this->message_id);
         $q->exec();
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->message_id && $perms->checkModuleItem('forums', 'add')) {
         $this->message_date = $q->dbfnNowWithTZ();
         if ($msg = parent::store()) {
             return $msg;
         }
         $q->addTable('forum_messages');
         $q->addQuery('count(message_id), MAX(message_date)');
         $q->addWhere('message_forum = ' . (int) $this->message_forum);
         $reply = $q->fetchRow();
         //update forum descriptor
         $forum = new CForum();
         $forum->load($AppUI, $this->message_forum);
         $forum->forum_message_count = $reply[0];
         /*
          * Note: the message_date here has already been adjusted for the
          *    timezone above, so don't do it again!
          */
         $forum->forum_last_date = $this->message_date;
         $forum->forum_last_id = $this->message_id;
         $forum->store($AppUI);
         $this->sendWatchMail(false);
         $stored = true;
     }
     return $stored;
 }
Esempio n. 9
0
 public function install()
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     $q->createTable('links');
     $q->createDefinition('(
         link_id int( 11 ) NOT NULL AUTO_INCREMENT ,
         link_url varchar( 255 ) NOT NULL default "",
         link_project int( 11 ) NOT NULL default "0",
         link_task int( 11 ) NOT NULL default "0",
         link_name varchar( 255 ) NOT NULL default "",
         link_parent int( 11 ) default "0",
         link_description text,
         link_owner int( 11 ) default "0",
         link_date datetime default NULL ,
         link_icon varchar( 20 ) default "obj/",
         link_category int( 11 ) NOT NULL default "0",
         PRIMARY KEY ( link_id ) ,
         KEY idx_link_task ( link_task ) ,
         KEY idx_link_project ( link_project ) ,
         KEY idx_link_parent ( link_parent )
         ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ');
     $q->exec($sql);
     $i = 0;
     $linkTypes = array('Unknown', 'Document', 'Application');
     foreach ($linkTypes as $linkType) {
         $q->clear();
         $q->addTable('sysvals');
         $q->addInsert('sysval_key_id', 1);
         $q->addInsert('sysval_title', 'LinkType');
         $q->addInsert('sysval_value', $linkType);
         $q->addInsert('sysval_value_id', $i);
         $q->exec();
         $i++;
     }
     $perms = $AppUI->acl();
     return $perms->registerModule('Links', 'links');
 }
Esempio n. 10
0
 public function authenticate($username, $password)
 {
     global $db, $AppUI;
     $this->username = $username;
     $q = new w2p_Database_Query();
     $q->addTable('users');
     $q->addQuery('user_id, user_password');
     $q->addWhere('user_username = \'' . $username . '\'');
     if (!($rs = $q->exec())) {
         $q->clear();
         return false;
     }
     if (!($row = $q->fetchRow())) {
         $q->clear();
         return false;
     }
     $this->user_id = $row['user_id'];
     $q->clear();
     if (MD5($password) == $row['user_password']) {
         return true;
     }
     return false;
 }
Esempio n. 11
0
 /**
  * Post Request Handler
  *
  * This method is called when a request is a POST
  *
  * @return array
  */
 public function executePost()
 {
     /**
      * @todo Remove this once we figure out how to reference vars in file
      * that is autoloaded
      */
     global $tracking_dynamics;
     $valid = $this->hasRequiredParameters($this->requiredParams);
     if ($valid instanceof Frapi_Error) {
         return $valid;
     }
     $username = $this->getParam('username');
     $password = $this->getParam('password');
     $project_id = $this->getParam('project_id', self::TYPE_INT);
     $hassign = $this->getParam('hassign');
     $hdependencies = $this->getParam('hdependencies');
     $notify = $this->getParam('task_notify');
     $comment = $this->getParam('email_comment');
     $task_id = $this->getParam('task_id');
     $adjustStartDate = $this->getParam('set_task_start_date');
     $task = new CTask();
     // Attempt to login as user, a little bit of a hack as we currently
     // require the $_POST['login'] var to be set as well as a global AppUI
     $AppUI = new CAppUI();
     $GLOBALS['AppUI'] = $AppUI;
     $_POST['login'] = '******';
     if (!$AppUI->login($username, $password)) {
         throw new Frapi_Error('INVALID_LOGIN');
     }
     $post_data = array('task_id' => $this->getParam('task_id'), 'task_name' => $this->getParam('task_name'), 'task_status' => $this->getParam('task_status'), 'task_percent_complete' => $this->getParam('task_percent_complete'), 'task_milestone' => $this->getParam('task_milestone'), 'task_owner' => $this->getParam('task_owner'), 'task_access' => $this->getParam('task_access'), 'task_related_url' => $this->getParam('task_related_url'), 'task_parent' => $this->getParam('task_parent'), 'task_type' => $this->getParam('task_type'), 'task_target_budget' => $this->getParam('task_target_budget'), 'task_description' => $this->getParam('task_description'), 'task_start_date' => $this->getParam('task_start_date'), 'task_end_date' => $this->getParam('task_end_date'), 'task_duration' => $this->getParam('task_duration'), 'task_duration_type' => $this->getParam('task_duration_type'), 'task_dynamic' => $this->getParam('task_dynamic'), 'task_allow_other_user_tasklogs' => $this->getParam('task_allow_other_user_tasklogs'), 'task_project' => $this->getParam('task_project'), 'task_priority' => $this->getParam('task_priority'));
     // Include any files for handling module-specific requirements
     foreach (findTabModules('tasks', 'addedit') as $mod) {
         $fname = W2P_BASE_DIR . '/modules/' . $mod . '/tasks_dosql.addedit.php';
         if (file_exists($fname)) {
             require_once $fname;
         }
     }
     // Find the task if we are set
     $task_end_date = null;
     if ($task_id) {
         $task->load($task_id);
         $task_end_date = new w2p_Utilities_Date($task->task_end_date);
     }
     $task = new CTask();
     if (!$task->bind($post_data)) {
         throw new Frapi_Error('SAVE_ERROR', $task->getError());
     }
     if ($task->task_dynamic != 1) {
         $task_dynamic_delay = $this->getParam('task_dynamic_nodelay') ? $this->getParam('task_dynamic_nodelay') : '0';
         if (in_array($task->task_dynamic, $tracking_dynamics)) {
             $task->task_dynamic = $task_dynamic_delay ? 21 : 31;
         } else {
             $task->task_dynamic = $task_dynamic_delay ? 11 : 0;
         }
     }
     // Let's check if task_dynamic is unchecked
     if (!$this->getParam('task_dynamic')) {
         $task->task_dynamic = false;
     }
     // Make sure task milestone is set or reset as appropriate
     if ($this->getParam('task_milestone')) {
         $task->task_milestone = false;
     }
     //format hperc_assign user_id=percentage_assignment;user_id=percentage_assignment;user_id=percentage_assignment;
     $tmp_ar = explode(';', $this->getParam('hperc_assign'));
     $i_cmp = sizeof($tmp_ar);
     $hperc_assign_ar = array();
     for ($i = 0; $i < $i_cmp; $i++) {
         $tmp = explode('=', $tmp_ar[$i]);
         if (count($tmp) > 1) {
             $hperc_assign_ar[$tmp[0]] = $tmp[1];
         } elseif ($tmp[0] != '') {
             $hperc_assign_ar[$tmp[0]] = 100;
         }
     }
     // let's check if there are some assigned departments to task
     $task->task_departments = implode(',', $this->getParam('dept_ids', self::TYPE_ARRAY));
     // convert dates to SQL format first
     if ($task->task_start_date) {
         $date = new w2p_Utilities_Date($task->task_start_date);
         $task->task_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     $end_date = null;
     if ($task->task_end_date) {
         if (strpos($task->task_end_date, '2400') !== false) {
             $task->task_end_date = str_replace('2400', '2359', $task->task_end_date);
         }
         $end_date = new w2p_Utilities_Date($task->task_end_date);
         $task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL);
     }
     $error_array = $task->store($AppUI);
     // Return all the validation messages
     if ($error_array !== true) {
         $error_message = '';
         foreach ($error_array as $error) {
             $error_message .= $error . '. ';
         }
         throw new Frapi_Error('SAVE_ERROR', $error_message);
     }
     $task_parent = $this->getParam('task_parent') ? $this->getParam('task_parent', SELF::TYPE_INT) : 0;
     $old_task_parent = $this->getParam('old_task_parent') ? $this->getParam('old_task_parent', SELF::TYPE_INT) : 0;
     if ($task_parent != $old_task_parent) {
         $oldTask = new CTask();
         $oldTask->load($old_task_parent);
         $oldTask->updateDynamics(false);
     }
     // How to handle custom fields? Do we support it in api?
     // Now add any task reminders
     // If there wasn't a task, but there is one now, and
     // that task date is set, we need to set a reminder.
     if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) {
         $task->addReminder();
     }
     if (isset($hassign)) {
         $task->updateAssigned($hassign, $hperc_assign_ar);
     }
     if (isset($hdependencies)) {
         // && !empty($hdependencies)) {
         // there are dependencies set!
         // backup initial start and end dates
         $tsd = new w2p_Utilities_Date($task->task_start_date);
         $ted = new w2p_Utilities_Date($task->task_end_date);
         // updating the table recording the
         // dependency relations with this task
         $task->updateDependencies($hdependencies, $task_parent);
         // we will reset the task's start date based upon dependencies
         // and shift the end date appropriately
         if ($adjustStartDate && !is_null($hdependencies)) {
             // load already stored task data for this task
             $tempTask = new CTask();
             $tempTask->load($task->task_id);
             // shift new start date to the last dependency end date
             $nsd = new w2p_Utilities_Date($tempTask->get_deps_max_end_date($tempTask));
             // prefer Wed 8:00 over Tue 16:00 as start date
             $nsd = $nsd->next_working_day();
             // prepare the creation of the end date
             $ned = new w2p_Utilities_Date();
             $ned->copy($nsd);
             if (empty($task->task_start_date)) {
                 // appropriately calculated end date via start+duration
                 $ned->addDuration($task->task_duration, $task->task_duration_type);
             } else {
                 // calc task time span start - end
                 $d = $tsd->calcDuration($ted);
                 // Re-add (keep) task time span for end date.
                 // This is independent from $obj->task_duration.
                 // The value returned by Date::Duration() is always in hours ('1')
                 $ned->addDuration($d, '1');
             }
             // prefer tue 16:00 over wed 8:00 as an end date
             $ned = $ned->prev_working_day();
             $task->task_start_date = $nsd->format(FMT_DATETIME_MYSQL);
             $task->task_end_date = $ned->format(FMT_DATETIME_MYSQL);
             $q = new w2p_Database_Query();
             $q->addTable('tasks', 't');
             $q->addUpdate('task_start_date', $task->task_start_date);
             $q->addUpdate('task_end_date', $task->task_end_date);
             $q->addWhere('task_id = ' . (int) $task->task_id);
             $q->addWhere('task_dynamic <> 1');
             $q->exec();
             $q->clear();
         }
         $task->pushDependencies($task->task_id, $task->task_end_date);
     }
     //$task = (array)$task;
     $task->load($task_id);
     unset($task->_query, $task->_error, $task->_tbl_prefix, $task->_tbl, $task->_tbl_key, $task->_tbl_module);
     $this->data['task'] = $task;
     $this->data['success'] = true;
     return $this->toArray();
 }
Esempio n. 12
0
 public function userId($username)
 {
     global $db;
     $q = new w2p_Database_Query();
     $q->addTable('users');
     $q->addWhere('user_username = \'' . $username . '\'');
     $rs = $q->exec();
     $row = $rs->FetchRow();
     $q->clear();
     return $row['user_id'];
 }
Esempio n. 13
0
$q2 = new w2p_Database_Query();
$q2->addTable('projects');
$q2->addQuery('project_id, COUNT(t1.task_id) AS total_tasks');
$q2->addJoin('tasks', 't1', 'projects.project_id = t1.task_project', 'inner');
if ($where_list) {
    $q2->addWhere($where_list);
}
if ($project_id > 0) {
    $q2->addWhere('project_id = ' . $project_id);
}
$q2->addGroup('project_id');
$perms =& $AppUI->acl();
$projects = array();
$canViewTask = canView('tasks');
if ($canViewTask) {
    $prc = $q->exec();
    echo db_error();
    while ($row = $q->fetchRow()) {
        $projects[$row['project_id']] = $row;
    }
    $prc2 = $q2->fetchRow();
    echo db_error();
    while ($row2 = $q2->fetchRow()) {
        if ($projects[$row2['project_id']]) {
            array_push($projects[$row2['project_id']], $row2);
        }
    }
}
$q->clear();
$q2->clear();
$q->addQuery('tasks.task_id, task_parent, task_name');
Esempio n. 14
0
 public static function updateHoursWorked($taskId, $totalHours)
 {
     $q = new w2p_Database_Query();
     $q->addTable('tasks');
     $q->addUpdate('task_hours_worked', $totalHours + 0);
     $q->addWhere('task_id = ' . $taskId);
     $q->exec();
     $q->clear();
     $q->addTable('tasks');
     $q->addQuery('task_project');
     $q->addWhere('task_id = ' . $taskId);
     $project_id = $q->loadResult();
     CProject::updateHoursWorked($project_id);
 }
Esempio n. 15
0
 // one session or many?
 if ($_GET['out_session'] && $_GET['out_user_log_id']) {
     $boot_user_session = $_GET['out_session'];
     $boot_user_log_id = w2PgetParam($_GET, 'out_user_log_id', null);
     $boot_query_row = false;
 } else {
     if ($canEdit && $canDelete && $logoutUserFlag) {
         // query for all sessions open for a given user
         $r = new w2p_Database_Query();
         $r->addTable('sessions', 's');
         $r->addQuery('DISTINCT(session_id), user_access_log_id');
         $r->addJoin('user_access_log', 'ual', 'session_user = user_access_log_id');
         $r->addWhere('user_id = ' . (int) $boot_user_id);
         $r->addOrder('user_access_log_id');
         //execute query and fetch results
         $r->exec();
         $boot_query_row = $r->fetchRow();
         if ($boot_query_row) {
             $boot_user_session = $boot_query_row['session_id'];
             $boot_user_log_id = $boot_query_row['user_access_log_id'];
         }
     }
 }
 do {
     if ($boot_user_id == $AppUI->user_id && $boot_user_session == $_COOKIE['PHPSESSID']) {
         $AppUI->resetPlace();
         $AppUI->redirect('logout=-1');
     } else {
         addHistory('login', $boot_user_id, 'logout', $details);
         w2PsessionDestroy($boot_user_session, $boot_user_log_id);
     }
Esempio n. 16
0
 public function delete()
 {
     $q = new w2p_Database_Query();
     if ($this->sysval_title) {
         $q->setDelete('sysvals');
         $q->addWhere('sysval_title = \'' . $this->sysval_title . '\'');
         if (!$q->exec()) {
             $q->clear();
             return get_class($this) . '::delete failed <br />' . db_error();
         }
     }
     return null;
 }
Esempio n. 17
0
 /**
  * @Function for update table user_acces_log in field date_time_lost_action
  */
 public function updateLastAction($last_insert_id)
 {
     if ($last_insert_id > 0) {
         $q = new w2p_Database_Query();
         $q->addTable('user_access_log');
         $q->addUpdate('date_time_last_action', "'" . $q->dbfnNowWithTZ() . "'", false, true);
         $q->addWhere('user_access_log_id = ' . $last_insert_id);
         $q->exec();
     }
 }
Esempio n. 18
0
$projTasks = array();
global $task_parent_options;
$task_parent_options = '';
// Now lets get non-root tasks, grouped by the task parent
$q = new w2p_Database_Query();
$q->addQuery('task_id, task_name, task_end_date, task_start_date, task_milestone, task_parent, task_dynamic');
$q->addTable('tasks');
$q->addWhere('task_project = ' . (int) $task_project);
$q->addWhere('task_id <> task_parent');
$q->addOrder('task_start_date');
$parents = array();
$projTasksWithEndDates = array(0 => $AppUI->_('None'));
//arrays contains task end date info for setting new task start date as maximum end date of dependenced tasks
global $all_tasks;
$all_tasks = array();
$sub_tasks = $q->exec();
if ($sub_tasks) {
    while ($sub_task = $q->fetchRow()) {
        // Build parent/child task list
        $parents[$sub_task['task_parent']][] = $sub_task['task_id'];
        $all_tasks[$sub_task['task_id']] = $sub_task;
        build_date_list($projTasksWithEndDates, $sub_task);
    }
}
$q->clear();
// let's iterate root tasks
foreach ($root_tasks as $root_task) {
    build_date_list($projTasksWithEndDates, $root_task);
    if ($root_task['task_id'] != $task_id) {
        constructTaskTree_pd($root_task, $parents, $all_tasks);
    }
Esempio n. 19
0
 public function remove()
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     $q->dropTable('planner');
     $q->exec();
     /**/
     $perms = $AppUI->acl();
     return $perms->unregisterModule('planner');
 }
Esempio n. 20
0
 $q->addTable('user_tasks');
 $q->addWhere('task_id = ' . (int) $task_id);
 $sql_user = $q->exec();
 $users = null;
 while ($Task_User = db_fetch_assoc($sql_user)) {
     if ($users != null) {
         $users .= ', ';
     }
     $q->clear();
     $q = new w2p_Database_Query();
     $q->addTable('users', 'u');
     $q->addTable('contacts', 'c');
     $q->addQuery('contact_first_name, contact_last_name');
     $q->addWhere('u.user_contact = c.contact_id');
     $q->addWhere('user_id = ' . (int) $Task_User['user_id']);
     $sql_user_array = $q->exec();
     $q->clear();
     $user_list = db_fetch_assoc($sql_user_array);
     $users .= $user_list['contact_first_name'] . ' ' . $user_list['contact_last_name'];
 }
 $str = '<tr>';
 if ($project_id == 0) {
     $str .= '<td>' . $Tasks['project_name'] . '</td>';
 }
 $str .= '<td>';
 $str .= $Tasks['task_id'] == $Tasks['task_parent'] ? '' : '<img src="' . w2PfindImage('corner-dots.gif') . '" width="16" height="12" border="0" alt="" />';
 $str .= '&nbsp;<a href="?m=tasks&a=view&task_id=' . $Tasks['task_id'] . '">' . $Tasks['task_name'] . '</a></td>';
 $str .= '<td>' . nl2br($Tasks['task_description']) . '</td>';
 $str .= '<td>' . $users . '</td>';
 $str .= '<td align="center">';
 $start_date != ' ' ? $str .= $start_date->format($df) . '</td>' : ($str .= ' </td>');
Esempio n. 21
0
 /**
  *	Default delete method
  *
  *	Can be overloaded/supplemented by the child class
  *	@return null|string null if successful otherwise returns and error message
  */
 public function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if (!$this->canDelete($msg)) {
         return $msg;
     }
     $q = new w2p_Database_Query();
     $q->setDelete($this->_tbl);
     $q->addWhere($this->_tbl_key . ' = \'' . $this->{$k} . '\'');
     $result = !$q->exec() ? db_error() : null;
     if (!$result) {
         // only record history if deletion actually occurred
         addHistory($this->_tbl, $this->{$k}, 'delete');
     }
     $q->clear();
     return $result;
 }
Esempio n. 22
0
 public static function updatePercentComplete($project_id)
 {
     $working_hours = w2PgetConfig('daily_working_hours') ? w2PgetConfig('daily_working_hours') : 8;
     $q = new w2p_Database_Query();
     $q->addTable('projects');
     $q->addQuery('SUM(t1.task_duration * t1.task_percent_complete * IF(t1.task_duration_type = 24, ' . $working_hours . ', t1.task_duration_type)) / SUM(t1.task_duration * IF(t1.task_duration_type = 24, ' . $working_hours . ', t1.task_duration_type)) AS project_percent_complete');
     $q->addJoin('tasks', 't1', 'projects.project_id = t1.task_project', 'inner');
     $q->addWhere('project_id = ' . $project_id . ' AND t1.task_id = t1.task_parent');
     $project_percent_complete = $q->loadResult();
     $q->clear();
     $q->addTable('projects');
     $q->addUpdate('project_percent_complete', $project_percent_complete);
     $q->addWhere('project_id  = ' . (int) $project_id);
     $q->exec();
     global $AppUI;
     CTask::storeTokenTask($AppUI, $project_id);
 }
Esempio n. 23
0
 public function indexStrings()
 {
     global $w2Pconfig;
     $nwords_indexed = 0;
     /* Workaround for indexing large files:
      ** Based on the value defined in config data,
      ** files with file_size greater than specified limit
      ** are not indexed for searching.
      ** Negative value :<=> no filesize limit
      */
     $index_max_file_size = w2PgetConfig('index_max_file_size', 0);
     if ($this->file_size > 0 && ($index_max_file_size < 0 || (int) $this->file_size <= $index_max_file_size * 1024)) {
         // get the parser application
         $parser = $w2Pconfig['parser_' . $this->file_type];
         if (!$parser) {
             $parser = $w2Pconfig['parser_default'];
         }
         if (!$parser) {
             return false;
         }
         // buffer the file
         $this->_filepath = W2P_BASE_DIR . '/files/' . $this->file_project . '/' . $this->file_real_filename;
         if (file_exists($this->_filepath)) {
             $fp = fopen($this->_filepath, 'rb');
             $x = fread($fp, $this->file_size);
             fclose($fp);
             // parse it
             $parser = $parser . ' ' . $this->_filepath;
             $pos = strpos($parser, '/pdf');
             /*
              * TODO: I *really* hate using error surpression here and I would
              *   normally just detect if safe_mode is on and if it was, skip
              *   this call. Unfortunately, safe_mode has been deprecated in
              *   5.3 and will be removed in 5.4
              */
             if (false !== $pos) {
                 $x = @shell_exec(`{$parser} -`);
             } else {
                 $x = @shell_exec(`{$parser}`);
             }
             // if nothing, return
             if (strlen($x) < 1) {
                 return 0;
             }
             // remove punctuation and parse the strings
             $x = str_replace(array('.', ',', '!', '@', '(', ')'), ' ', $x);
             $warr = explode(' ', $x);
             $wordarr = array();
             $nwords = count($warr);
             for ($x = 0; $x < $nwords; $x++) {
                 $newword = $warr[$x];
                 if (!preg_match('[!"#$%&\'()*+,\\-./:;<=>?@[\\\\]^_`{|}~]', $newword) && mb_strlen(mb_trim($newword)) > 2 && !preg_match('[0-9]', $newword)) {
                     $wordarr[$newword] = $x;
                 }
             }
             // filter out common strings
             $ignore = w2PgetSysVal('FileIndexIgnoreWords');
             $ignore = str_replace(' ,', ',', $ignore);
             $ignore = str_replace(', ', ',', $ignore);
             $ignore = explode(',', $ignore);
             foreach ($ignore as $w) {
                 unset($wordarr[$w]);
             }
             $nwords_indexed = count($wordarr);
             // insert the strings into the table
             while (list($key, $val) = each($wordarr)) {
                 $q = new w2p_Database_Query();
                 $q->addTable('files_index');
                 $q->addReplace('file_id', $this->file_id);
                 $q->addReplace('word', $key);
                 $q->addReplace('word_placement', $val);
                 $q->exec();
                 $q->clear();
             }
         } else {
             //TODO: if the file doesn't exist.. should we delete the db record?
         }
     }
     $q = new w2p_Database_Query();
     $q->addTable('files');
     $q->addUpdate('file_indexed', 1);
     $q->addWhere('file_id = ' . $this->file_id);
     $q->exec();
     return $nwords_indexed;
 }
 public function unregisterModule($module_value)
 {
     if ($module_value != '') {
         $q = new w2p_Database_Query();
         $q->setDelete('gacl_axo');
         $q->addWhere("value = '{$module_value}'");
         $q->exec();
         return true;
     }
     return false;
 }
Esempio n. 25
0
         //print_r($bulk_task_dependency);die;
         if ($bulk_task_dependency == '0') {
             $upd_task->task_dynamic = 0;
             $upd_task->store($AppUI);
             $q = new w2p_Database_Query();
             $q->setDelete('task_dependencies');
             $q->addWhere('dependencies_task_id=' . $upd_task->task_id);
             $q->exec();
         } elseif (!($bulk_task_dependency == $upd_task->task_id)) {
             $upd_task->task_dynamic = 31;
             $upd_task->store($AppUI);
             $q = new w2p_Database_Query();
             $q->addTable('task_dependencies');
             $q->addReplace('dependencies_task_id', $upd_task->task_id);
             $q->addReplace('dependencies_req_task_id', $bulk_task_dependency);
             $q->exec();
             //Lets recalc the dependency
             $dep_task = new CTask();
             $dep_task->load($bulk_task_dependency);
             if ($dep_task->task_id) {
                 $dep_task->shiftDependentTasks();
             }
         }
     }
 }
 //Action: Modify priority
 if (isset($_POST['bulk_task_priority']) && $bulk_task_priority != '') {
     if ($upd_task->task_id) {
         $upd_task->task_priority = $bulk_task_priority;
         $result = $upd_task->store($AppUI);
         if (is_array($result)) {
Esempio n. 26
0
 public function hook_cron()
 {
     if (w2PgetConfig('system_update_check', true)) {
         $lastCheck = w2PgetConfig('system_update_last_check', '');
         $nowDate = new DateTime("now");
         if ('' == $lastCheck) {
             $checkForUpdates = true;
         } else {
             $systemDate = new DateTime($lastCheck);
             $difference = 0;
             //$nowDate->diff($systemDate)->format('%d');
             $checkForUpdates = $difference >= 7 ? true : false;
         }
         if ($checkForUpdates) {
             $AppUI = new w2p_Core_CAppUI();
             $configList = array();
             $moduleList = $AppUI->getLoadableModuleList();
             foreach ($moduleList as $module) {
                 $configList[$module['mod_directory']] = $module['mod_version'];
             }
             $configList['w2p_ver'] = $AppUI->getVersion();
             $configList['php_ver'] = PHP_VERSION;
             $configList['database'] = $this->_w2Pconfig['dbtype'];
             $configList['server'] = $_SERVER['SERVER_SOFTWARE'];
             $configList['connector'] = php_sapi_name();
             $configList['database_ver'] = mysql_get_client_info();
             $libraries = array('tidy', 'json', 'libxml', 'mysql');
             foreach ($libraries as $library) {
                 $configList[$library . '_extver'] = phpversion($library);
             }
             if (function_exists('gd_info')) {
                 $lib_version = gd_info();
                 $configList['gd_extver'] = $lib_version['GD Version'];
             }
             if (function_exists('curl_version')) {
                 $lib_version = curl_version();
                 $configList['curl_extver'] = $lib_version['version'];
             }
             $request = new w2p_Utilities_HTTPRequest('http://stats.web2project.net');
             $request->addParameters($configList);
             $result = $request->processRequest();
             $data = json_decode($result);
             $q = new w2p_Database_Query();
             $q->addTable('config');
             if ('' == w2PgetConfig('available_version', '')) {
                 $q->addInsert('config_name', 'available_version');
                 $q->addInsert('config_value', $data->w2p_ver);
                 $q->addInsert('config_group', 'admin_system');
                 $q->addInsert('config_type', 'text');
             } else {
                 $q->addUpdate('config_value', $data->w2p_ver);
                 $q->addWhere("config_name  = 'available_version'");
             }
             $q->exec();
             $q->clear();
             $q->addTable('config');
             $q->addUpdate('config_value', date('Y-m-d H:i:s'));
             $q->addWhere("config_name  = 'system_update_last_check'");
             $q->exec();
         }
     }
 }
Esempio n. 27
0
$q = new w2p_Database_Query();
$pinned_only = (int) w2PgetParam($_GET, 'pinned', 0);
if (isset($_GET['pin'])) {
    $pin = (int) w2PgetParam($_GET, 'pin', 0);
    $msg = '';
    // load the record data
    if ($pin) {
        $q->addTable('user_task_pin');
        $q->addInsert('user_id', $AppUI->user_id);
        $q->addInsert('task_id', $task_id);
    } else {
        $q->setDelete('user_task_pin');
        $q->addWhere('user_id = ' . (int) $AppUI->user_id);
        $q->addWhere('task_id = ' . (int) $task_id);
    }
    if (!$q->exec()) {
        $AppUI->setMsg('ins/del err', UI_MSG_ERROR, true);
    } else {
        $q->clear();
    }
    $AppUI->redirect('', -1);
}
$AppUI->savePlace();
$durnTypes = w2PgetSysVal('TaskDurationType');
$taskPriority = w2PgetSysVal('TaskPriority');
$task_project = $project_id;
$task_sort_item1 = w2PgetParam($_GET, 'task_sort_item1', '');
$task_sort_type1 = w2PgetParam($_GET, 'task_sort_type1', '');
$task_sort_item2 = w2PgetParam($_GET, 'task_sort_item2', '');
$task_sort_type2 = w2PgetParam($_GET, 'task_sort_type2', '');
$task_sort_order1 = (int) w2PgetParam($_GET, 'task_sort_order1', 0);
Esempio n. 28
0
}
$perms =& $AppUI->acl();
if (!canView('forums')) {
    $AppUI->redirect('m=public&a=access_denied');
}
##
## Change forum watches
##
$watch = w2PgetParam($_POST, 'watch', '');
if ($watch) {
    // clear existing watches
    $q = new w2p_Database_Query();
    $q->setDelete('forum_watch');
    $q->addWhere('watch_user = '******'watch_' . $watch . ' IS NOT NULL');
    if (!$q->exec()) {
        $AppUI->setMsg(db_error(), UI_MSG_ERROR);
        $q->clear();
    } else {
        $q->clear();
        foreach ($_POST as $k => $v) {
            if (strpos($k, 'forum_') !== false) {
                $q->addTable('forum_watch');
                $q->addInsert('watch_user', $AppUI->user_id);
                $q->addInsert('watch_' . $watch, substr($k, 6));
                if (!$q->exec()) {
                    $AppUI->setMsg(db_error(), UI_MSG_ERROR);
                } else {
                    $AppUI->setMsg('Watch updated', UI_MSG_OK);
                }
                $q->clear();
function projects_list_data($user_id = false)
{
    global $AppUI, $addPwOiD, $buffer, $company, $company_id, $company_prefix, $deny, $department, $dept_ids, $w2Pconfig, $orderby, $orderdir, $tasks_problems, $owner, $projectTypeId, $search_text, $project_type;
    $addProjectsWithAssignedTasks = $AppUI->getState('addProjWithTasks') ? $AppUI->getState('addProjWithTasks') : 0;
    // get any records denied from viewing
    $obj = new CProject();
    $deny = $obj->getDeniedRecords($AppUI->user_id);
    // Let's delete temproary tables
    $q = new w2p_Database_Query();
    $q->setDelete('tasks_problems');
    $q->exec();
    $q->clear();
    $q->setDelete('tasks_users');
    $q->exec();
    $q->clear();
    // support task problem logs
    $q->addInsertSelect('tasks_problems');
    $q->addTable('tasks');
    $q->addQuery('task_project, task_log_problem');
    $q->addJoin('task_log', 'tl', 'tl.task_log_task = task_id', 'inner');
    $q->addWhere('task_log_problem = 1');
    $q->addGroup('task_project');
    $tasks_problems = $q->exec();
    $q->clear();
    if ($addProjectsWithAssignedTasks) {
        // support users tasks
        $q->addInsertSelect('tasks_users');
        $q->addTable('tasks');
        $q->addQuery('task_project');
        $q->addQuery('ut.user_id');
        $q->addJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
        if ($user_id) {
            $q->addWhere('ut.user_id = ' . (int) $user_id);
        }
        $q->addOrder('task_end_date DESC');
        $q->addGroup('task_project');
        $tasks_users = $q->exec();
        $q->clear();
    }
    // add Projects where the Project Owner is in the given department
    if ($addPwOiD && isset($department)) {
        $owner_ids = array();
        $q->addTable('users');
        $q->addQuery('user_id');
        $q->addJoin('contacts', 'c', 'c.contact_id = user_contact', 'inner');
        $q->addWhere('c.contact_department = ' . (int) $department);
        $owner_ids = $q->loadColumn();
        $q->clear();
    }
    if (isset($department)) {
        //If a department is specified, we want to display projects from the department, and all departments under that, so we need to build that list of departments
        $dept_ids = array();
        $q->addTable('departments');
        $q->addQuery('dept_id, dept_parent');
        $q->addOrder('dept_parent,dept_name');
        $rows = $q->loadList();
        addDeptId($rows, $department);
        $dept_ids[] = isset($department->dept_id) ? $department->dept_id : 0;
        $dept_ids[] = $department > 0 ? $department : 0;
    }
    $q->clear();
    // retrieve list of records
    // modified for speed
    // by Pablo Roca (pabloroca@mvps.org)
    // 16 August 2003
    // get the list of permitted companies
    $obj = new CCompany();
    $companies = $obj->getAllowedRecords($AppUI->user_id, 'companies.company_id,companies.company_name', 'companies.company_name');
    if (count($companies) == 0) {
        $companies = array();
    }
    $q->addTable('projects', 'pr');
    $q->addQuery('pr.project_id, project_status, project_color_identifier,
		project_type, project_name, project_description, project_scheduled_hours as project_duration,
		project_parent, project_original_parent, project_percent_complete,
		project_color_identifier, project_company,
        company_name, project_status, project_last_task as critical_task,
        tp.task_log_problem, user_username, project_active');
    $fields = w2p_Core_Module::getSettings('projects', 'index_list');
    unset($fields['department_list']);
    // added as an alias below
    foreach ($fields as $field => $text) {
        $q->addQuery($field);
    }
    $q->addQuery('CONCAT(ct.contact_first_name, \' \', ct.contact_last_name) AS owner_name');
    $q->addJoin('users', 'u', 'pr.project_owner = u.user_id');
    $q->addJoin('contacts', 'ct', 'ct.contact_id = u.user_contact');
    $q->addJoin('tasks_problems', 'tp', 'pr.project_id = tp.task_project');
    if ($addProjectsWithAssignedTasks) {
        $q->addJoin('tasks_users', 'tu', 'pr.project_id = tu.task_project');
    }
    if (!isset($department) && $company_id && !$addPwOiD) {
        $q->addWhere('pr.project_company = ' . (int) $company_id);
    }
    if ($project_type > -1) {
        $q->addWhere('pr.project_type = ' . (int) $project_type);
    }
    if (isset($department) && !$addPwOiD) {
        $q->addWhere('project_departments.department_id in ( ' . implode(',', $dept_ids) . ' )');
    }
    if ($user_id && $addProjectsWithAssignedTasks) {
        $q->addWhere('(tu.user_id = ' . (int) $user_id . ' OR pr.project_owner = ' . (int) $user_id . ' )');
    } elseif ($user_id) {
        $q->addWhere('pr.project_owner = ' . (int) $user_id);
    }
    if ($owner > 0) {
        $q->addWhere('pr.project_owner = ' . (int) $owner);
    }
    if (mb_trim($search_text)) {
        $q->addWhere('pr.project_name LIKE \'%' . $search_text . '%\' OR pr.project_description LIKE \'%' . $search_text . '%\'');
    }
    // Show Projects where the Project Owner is in the given department
    if ($addPwOiD && !empty($owner_ids)) {
        $q->addWhere('pr.project_owner IN (' . implode(',', $owner_ids) . ')');
    }
    $orderby = 'project_company' == $orderby ? 'company_name' : $orderby;
    $q->addGroup('pr.project_id');
    $q->addOrder($orderby . ' ' . $orderdir);
    $prj = new CProject();
    $prj->setAllowedSQL($AppUI->user_id, $q, null, 'pr');
    $dpt = new CDepartment();
    $projects = $q->loadList();
    // get the list of permitted companies
    $companies = arrayMerge(array('0' => $AppUI->_('All')), $companies);
    $company_array = $companies;
    //get list of all departments, filtered by the list of permitted companies.
    $q->clear();
    $q->addTable('companies');
    $q->addQuery('company_id, company_name, dep.*');
    $q->addJoin('departments', 'dep', 'companies.company_id = dep.dept_company');
    $q->addOrder('company_name,dept_parent,dept_name');
    $obj->setAllowedSQL($AppUI->user_id, $q);
    $dpt->setAllowedSQL($AppUI->user_id, $q);
    $rows = $q->loadList();
    //display the select list
    $buffer = '<select name="department" id="department" onChange="document.pickCompany.submit()" class="text" style="width: 200px;">';
    $company = '';
    foreach ($company_array as $key => $c_name) {
        $buffer .= '<option value="' . $company_prefix . $key . '" style="font-weight:bold;"' . ($company_id == $key ? 'selected="selected"' : '') . '>' . $c_name . '</option>' . "\n";
        foreach ($rows as $row) {
            if ($row['dept_parent'] == 0) {
                if ($key == $row['company_id']) {
                    if ($row['dept_parent'] != null) {
                        findchilddept($rows, $row['dept_id']);
                    }
                }
            }
        }
    }
    $buffer .= '</select>';
    return $projects;
}
Esempio n. 30
0
?>
:</td>
	<td>
<?php 
$tl = $AppUI->getPref('TASKLOGEMAIL');
$ta = $tl & 1;
$tt = $tl & 2;
$tp = $tl & 4;
$task_email_title = array();
$q = new w2p_Database_Query();
$q->addTable('task_contacts', 'tc');
$q->addJoin('contacts', 'c', 'c.contact_id = tc.contact_id', 'inner');
$q->addWhere('tc.task_id = ' . (int) $obj->task_id);
$q->addQuery('tc.contact_id');
$q->addQuery('c.contact_first_name, c.contact_last_name');
$req =& $q->exec();
$cidtc = array();
for ($req; !$req->EOF; $req->MoveNext()) {
    $cidtc[] = $req->fields['contact_id'];
    $task_email_title[] = $req->fields['contact_first_name'] . ' ' . $req->fields['contact_last_name'];
}
$q->clear();
$q->addTable('project_contacts', 'pc');
$q->addJoin('contacts', 'c', 'c.contact_id = pc.contact_id', 'inner');
$q->addWhere('pc.project_id = ' . (int) $obj->task_project);
$q->addQuery('pc.contact_id');
$q->addQuery('c.contact_first_name, c.contact_last_name');
$req =& $q->exec();
$cidpc = array();
$proj_email_title = array();
for ($req; !$req->EOF; $req->MoveNext()) {