Пример #1
0
 /**
  * Return all users that was active in past $active_in minutes (defautl is 15 minutes)
  *
  * @access public
  * @param integer $active_in
  * @return array
  */
 static function getWhoIsOnline($active_in = 15)
 {
     if ((int) $active_in < 1) {
         $active_in = 15;
     }
     $datetime = DateTimeValueLib::now();
     $datetime->advance(-1 * $active_in * 60);
     return Users::findAll(array('conditions' => array('`last_activity` > ?', $datetime)));
     // findAll
 }
Пример #2
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'cTime DESC';
     //$criteria->select = 'id,title';
     $model = new Users();
     $count = $model->count($criteria);
     $pager = new CPagination($count);
     $pager->pageSize = 100;
     $pager->applyLimit($criteria);
     $posts = $model->findAll($criteria);
     $this->render('index', array('pages' => $pager, 'posts' => $posts));
 }
Пример #3
0
 /**
  * Returns all User objects that belong to a group
  *
  * @param integer $group_id
  * @return User list
  */
 static function getUsersByGroup($group_id)
 {
     $all = self::findAll(array('conditions' => array('`group_id` = ?', $group_id)));
     $cond = '0';
     if (!$all) {
         return array();
     }
     //empty result, avoid query
     foreach ($all as $usr) {
         $cond .= ',' . $usr->getUserId();
     }
     $cond = '(' . $cond . ') ';
     return Users::findAll(array('conditions' => array('`id` in ' . $cond)));
 }
Пример #4
0
<?php

require_once '../../bootstrap.php';
use Pop\Db;
/*
 * Placing a class here is highly unorthodox.
 * This is just for example purposes only.
 */
class Users extends Db\Record
{
}
try {
    // Define DB credentials
    $db = Db\Db::factory('Mysqli', array('database' => 'helloworld', 'host' => 'localhost', 'username' => 'hello', 'password' => '12world34'));
    Users::setDb($db);
    $users = Users::findAll('id ASC', array('username' => '%test%'), '3, 4');
    print_r($users->rows);
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Пример #5
0
 /**
  * Delete project
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     $wsIds = $this->getAllSubWorkspacesQuery();
     if ($wsIds) {
         $ws = $this->getSubWorkspaces();
         if (isset($ws) && !is_null($ws)) {
             $wsToDelete = array();
             $wsToMove = array();
             $users = Users::findAll(array("conditions" => "personal_project_id in ({$wsIds})"));
             foreach ($ws as $w) {
                 $canDelete = $w->canDelete(logged_user());
                 if ($users && $canDelete) {
                     foreach ($users as $user) {
                         if ($user->getPersonalProjectId() == $w->getId()) {
                             $canDelete = false;
                             break;
                         }
                     }
                 }
                 if ($canDelete) {
                     $wsToDelete[] = $w;
                 } else {
                     $wsToMove[] = $w;
                 }
             }
             if (count($wsToMove) > 0) {
                 //Find the new parents
                 $moves = array();
                 foreach ($wsToMove as $w) {
                     $parentIds = $w->getParentIds();
                     for ($i = $w->getDepth() - 1; $i > 0; $i--) {
                         if ($parentIds[$i] == $this->getId()) {
                             $moves[] = array($w, $this->getParentWorkspace());
                             break;
                         } else {
                             $found = false;
                             for ($j = 0; $j < count($wsToMove); $j++) {
                                 if ($parentIds[$i] == $wsToMove[$j]->getId()) {
                                     $moves[] = array($w, $wsToMove[$j]);
                                     $found = true;
                                     break;
                                 }
                             }
                             if ($found) {
                                 break;
                             }
                         }
                     }
                 }
             }
             foreach ($wsToDelete as $w) {
                 $w->deleteSingle();
             }
             if (isset($moves)) {
                 foreach ($moves as $move) {
                     $move[0]->setParentWorkspace($move[1]);
                     $move[0]->save();
                 }
             }
         }
     }
     return $this->deleteSingle();
 }
Пример #6
0
 function getExternalUsers()
 {
     return Users::findAll(array('conditions' => '`company_id` IN (SELECT `id` FROM `' . TABLE_PREFIX . 'companies` WHERE `client_of_id` <> 0)'));
 }
Пример #7
0
/**
 * Do daily taks
 *
 * @param void
 * @return null
 */
function system_handle_on_daily()
{
    ProjectObjectViews::cleanUp();
    $priorities_images = array(PRIORITY_URGENT => 'assets/images/icons/priority/urgent.png', PRIORITY_HIGHEST => 'assets/images/icons/priority/highest.gif', PRIORITY_HIGH => 'assets/images/icons/priority/high.gif', PRIORITY_NORMAL => 'assets/images/icons/priority/normal.gif', PRIORITY_LOW => 'assets/images/icons/priority/low.gif', PRIORITY_LOWEST => 'assets/images/icons/priority/lowest.gif', PRIORITY_HOLD => 'assets/images/icons/priority/hold.png', '-99' => 'assets/images/icons/priority/unknown.png');
    $pages = array();
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $sql = "select id, name from healingcrystals_project_objects where project_id='" . TASK_LIST_PROJECT_ID . "' and type='Page'";
    $result = mysql_query($sql, $link);
    while ($entry = mysql_fetch_assoc($result)) {
        list($name, ) = explode('-', $entry['name']);
        $name = trim($name);
        $pages[$name] = $entry['id'];
    }
    $current_time = time();
    $users = Users::findAll();
    foreach ($users as $user) {
        $flag = 1;
        $message = '';
        $name = $user->getName();
        if (array_key_exists($name, $pages)) {
            $page = new Page($pages[$name]);
            if ($page) {
                $sql = "select id from healingcrystals_project_objects where parent_id='" . $pages[$name] . "' and parent_type='Page' and type='Task' and completed_on is null and priority is null and created_on>='" . date('Y-m-d H:i:s', $current_time - 1 * 24 * 60 * 60) . "' order by created_on";
                $result = mysql_query($sql, $link);
                if (mysql_num_rows($result)) {
                    $show_task_list = true;
                } else {
                    $show_task_list = false;
                }
                if (date('N') == '1' || $show_task_list) {
                    $message .= '<style>
		.odd {background-color:#ffffff;}
		.even{background-color:#eeeeee;}
	</style>
	<table>
		<tr>
			<td colspan="3">Task List: ' . $name . '</td>
		</tr>
		<tr>
			<td align="center">Priority</td>
			<td>Task</td>
			<td>&nbsp;</td>
		</tr>';
                    $tasks = Tasks::findOpenByObject($page);
                    foreach ($tasks as $task) {
                        $message .= '
		<tr class="' . ($flag % 2 === 1 ? 'odd' : 'even') . '">
			<td valign="top" align="center"><img  src="http://projects.ffbh.org/public/' . $priorities_images[$task->getPriority()] . '"/></td>
			<td valign="top">' . $task->getName() . '</td>
			<td valign="top"><a href="' . $task->getViewUrl() . '">View</a></td>
		</tr>';
                        $flag++;
                    }
                    $message .= '
	</table>';
                    $subject = 'projects: healingcrystals.com Task list';
                    $headers = 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                    $headers .= 'From: FFBH Reminder <*****@*****.**>' . "\r\n";
                    mail($user->getEmail(), $subject, $message, $headers);
                }
            }
        }
    }
    $sql = "select po.id, cast(if( pom.recurring_period_type='D', DATE_ADD(po.due_on, interval pom.recurring_period day), if(pom.recurring_period_type='W', DATE_ADD(po.due_on, interval pom.recurring_period week), if(pom.recurring_period_type='M', DATE_ADD(po.due_on, interval pom.recurring_period month), null ) ) ) as Date) as next_due_date, cast(DATE_ADD(now(), interval 0 day) as Date) as cur_date, cast(if(isnull(pom.email_reminder_unit), null, if( pom.email_reminder_unit='D', DATE_ADD(po.due_on, interval pom.email_reminder_period day), if(pom.email_reminder_unit='W', DATE_ADD(po.due_on, interval pom.email_reminder_period week), if(pom.email_reminder_unit='M', DATE_ADD(po.due_on, interval pom.email_reminder_period month), null ) ) )\t) as Date) as reminder_date from healingcrystals_project_objects po inner join  healingcrystals_project_object_misc pom on po.id=pom.object_id where po.type='Task' and po.due_on is not null and po.due_on<=now() and po.completed_on is null and pom.recurring_period_condition='after_due_date' and if(pom.recurring_end_date is not null and pom.recurring_end_date!='0000-00-00', if(pom.recurring_end_date>=now(), 1, 0), 1)=1 having next_due_date=cur_date";
    $result = mysql_query($sql);
    while ($entry = mysql_fetch_assoc($result)) {
        $task = new Task($entry['id']);
        $action = $task->complete(new AnonymousUser('auto', '*****@*****.**'));
        if (!empty($entry['reminder_date']) && $entry['cur_date'] == $entry['reminder_date']) {
            $sql02 = "select id from " . TABLE_PREFIX . "project_objects where type='Task' and project_id='" . $task->getProjectId() . "' and milestone_id='" . $task->getMilestoneId() . "' and parent_id='" . $task->getParentId() . "' order by id desc limit 0, 1";
            $result02 = mysql_query($sql02);
            if (mysql_num_rows($result02)) {
                $info = mysql_fetch_assoc($result02);
                $recurring_task = new Task($info['id']);
                $parent = $recurring_task->getParent();
                $project = $recurring_task->getProject();
                $assignees = $recurring_task->getAssignees();
                $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold'));
                $due_date = $task->getDueOn();
                $due_date = date('m/d/Y', strtotime($due_date));
                $reminder_date = date('m/d/Y', strtotime($entry['reminder_date']));
                foreach ($assignees as $assignee) {
                    $assignees_string .= $assignee->getDisplayName() . ', ';
                }
                if (!empty($assignees_string)) {
                    $assignees_string = substr($assignees_string, 0, -2);
                } else {
                    $assignees_string = '--';
                }
                $reminders_sent = array();
                foreach ($assignees as $user) {
                    //if ($user->getEmail()=='*****@*****.**'){
                    $reminder = new Reminder();
                    $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $recurring_task->getId(), 'comment' => $comment));
                    $save = $reminder->save();
                    if ($save && !is_error($save)) {
                        $reminders_sent[] = $user->getDisplayName();
                        ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $recurring_task->getName(), 'object_url' => $recurring_task->getViewUrl(), 'object_type' => strtolower($recurring_task->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $recurring_task->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $recurring_task->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => $recurring_task->is_action_request_task() ? '' : 'none'), $recurring_task);
                    }
                    //}
                }
            }
        }
    }
    mysql_close($link);
}
 function add_reminders($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $popup_count = 0;
     $object->clearReminders(logged_user(), true);
     $typesC = array_var($_POST, 'reminder_type');
     if (!is_array($typesC)) {
         return;
     }
     $durationsC = array_var($_POST, 'reminder_duration');
     $duration_typesC = array_var($_POST, 'reminder_duration_type');
     $subscribersC = array_var($_POST, 'reminder_subscribers');
     foreach ($typesC as $context => $types) {
         $durations = $durationsC[$context];
         $duration_types = $duration_typesC[$context];
         $subscribers = $subscribersC[$context];
         for ($i = 0; $i < count($types); $i++) {
             $type = $types[$i];
             $duration = $durations[$i];
             $duration_type = $duration_types[$i];
             $minutes = $duration * $duration_type;
             $reminder = new ObjectReminder();
             $reminder->setMinutesBefore($minutes);
             $reminder->setType($type);
             $reminder->setContext($context);
             $reminder->setObject($object);
             if (isset($subscribers[$i])) {
                 $reminder->setUserId(0);
             } else {
                 $reminder->setUser(logged_user());
             }
             $date = $object->getColumnValue($context);
             if ($date instanceof DateTimeValue) {
                 $rdate = new DateTimeValue($date->getTimestamp() - $minutes * 60);
                 $reminder->setDate($rdate);
             }
             $reminder->save();
             $popup_count = $popup_count + ($type == 'reminder_popup' ? 1 : 0);
         }
     }
     if (count($popup_count) > 0 && GlobalCache::isAvailable()) {
         $user_ids = Users::findAll(array('id' => true));
         foreach ($user_ids as $uid) {
             GlobalCache::update('check_for_popup_reminders_' . $uid, 1);
         }
     }
 }
Пример #9
0
 function getAssignableUsers($project = null)
 {
     if ($this->isMemberOfOwnerCompany()) {
         return Users::getAll();
     }
     TimeIt::start('get assignable users');
     if ($project instanceof Project) {
         $ws = $project->getAllSubWorkspacesQuery(true);
     }
     $users = $this->getCompany()->getUsers();
     $uid = $this->getId();
     $cid = $this->getCompany()->getId();
     $tp = TABLE_PREFIX;
     $gids = "SELECT `group_id` FROM `{$tp}group_users` WHERE `user_id` = {$uid}";
     $q1 = "SELECT `project_id` FROM `{$tp}project_users` WHERE (`user_id` = {$uid} OR `user_id` IN ({$gids})) AND `can_assign_to_other` = '1'";
     $q2 = "SELECT `project_id` FROM `{$tp}project_users` WHERE (`user_id` = {$uid} OR `user_id` IN ({$gids})) AND `can_assign_to_owners` = '1'";
     if (isset($ws)) {
         $q1 .= " AND `project_id` IN ({$ws})";
         $q2 .= " AND `project_id` IN ({$ws})";
     }
     $query1 = "SELECT `user_id` FROM `{$tp}project_users` WHERE `project_id` IN ({$q1})";
     $query2 = "SELECT `user_id` FROM `{$tp}project_users` WHERE `project_id` IN ({$q2})";
     // get users from other client companies that share workspaces in which the user can assign to other clients' members
     $us1 = Users::findAll(array('conditions' => "`id` IN ({$query1}) AND `company_id` <> 1 AND `company_id` <> {$cid}"));
     // get users from the owner company that share workspaces in which the user can assign to owner company members
     $us2 = Users::findAll(array('conditions' => "`id` IN ({$query2}) AND `company_id` = 1"));
     $users = array_merge($users, $us1);
     $users = array_merge($users, $us2);
     TimeIt::stop();
     return $users;
 }
Пример #10
0
 /**
  * This function sets the selected billing values for all timeslots which lack any type of billing values (value set to 0). 
  * This function is used when users start to use billing in the system.
  * 
  * @return unknown_type
  */
 static function updateBillingValues()
 {
     $timeslots = Timeslots::findAll(array('conditions' => '`end_time` > 0 AND billing_id = 0 AND is_fixed_billing = 0 AND (object_manager = \'ProjectTasks\' OR object_manager = \'Projects\')', 'limit' => 500));
     $users = Users::findAll();
     $usArray = array();
     foreach ($users as $u) {
         $usArray[$u->getId()] = $u;
     }
     $pbidCache = array();
     $count = 0;
     foreach ($timeslots as $ts) {
         $user = $usArray[$ts->getUserId()];
         if (isset($user) && $user) {
             $billing_category_id = $user->getDefaultBillingId();
             if ($billing_category_id > 0) {
                 $object = $ts->getObject();
                 //Set billing info
                 if ($object instanceof ProjectDataObject && $object->getProject() instanceof Project || $object instanceof Project) {
                     $hours = $ts->getMinutes() / 60;
                     if ($object instanceof Project) {
                         $project = $object;
                     } else {
                         $project = $object->getProject();
                     }
                     $ts->setBillingId($billing_category_id);
                     if (!isset($pbidCache[$project->getId()])) {
                         $pbidCache[$project->getId()] = array();
                     }
                     if (isset($pbidCache[$project->getId()][$billing_category_id])) {
                         $hourly_billing = $pbidCache[$project->getId()][$billing_category_id];
                     } else {
                         $hourly_billing = $project->getBillingAmount($billing_category_id);
                         $pbidCache[$project->getId()][$billing_category_id] = $hourly_billing;
                     }
                     $ts->setHourlyBilling($hourly_billing);
                     $ts->setFixedBilling(round($hourly_billing * $hours, 2));
                     $ts->setIsFixedBilling(false);
                     $ts->save();
                     $count++;
                 }
             }
         } else {
             $ts->setIsFixedBilling(true);
             $ts->save();
         }
     }
     return $count;
 }
Пример #11
0
 /**
  * Return users that have auto assign value set to true
  *
  * @access public
  * @param void
  * @return array
  */
 function getAutoAssignUsers()
 {
     return Users::findAll(array('conditions' => '`company_id` = ' . DB::escape($this->getId()) . ' AND `auto_assign` > ' . DB::escape(0)));
     // findAll
 }
 function getCategoryUsers()
 {
     return Users::findAll(array('conditions' => 'default_billing_id = ' . $this->getId()));
 }