Пример #1
0
 function add_subscribers(ContentDataObject $object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $log_info = "";
     $subscribers = array_var($_POST, 'subscribers');
     $object->clearSubscriptions();
     if (is_array($subscribers)) {
         $user_ids = array();
         foreach ($subscribers as $key => $checked) {
             $user_id = substr($key, 5);
             if ($checked == "checked") {
                 $user = Contacts::findById($user_id);
                 if ($user instanceof Contact) {
                     $object->subscribeUser($user);
                     $log_info .= ($log_info == "" ? "" : ",") . $user->getId();
                     $user_ids[] = $user_id;
                 }
             }
         }
         Hook::fire('after_add_subscribers', array('object' => $object, 'user_ids' => $user_ids), $null);
         if ($log_info != "") {
             ApplicationLogs::createLog($object, ApplicationLogs::ACTION_SUBSCRIBE, false, true, true, $log_info);
         }
     }
 }
 /**
  *	
  * @param array $permissions with the member and the changed_pgs
  */
 function afterMemberPermissionChanged($permissions)
 {
     $member = array_var($permissions, 'member');
     //get all users in the set of permissions groups
     $permissionGroupIds = array();
     foreach (array_var($permissions, 'changed_pgs') as $pg_id) {
         $permissionGroupId = $pg_id;
         if (!in_array($permissionGroupId, $permissionGroupIds)) {
             $permissionGroupIds[] = $permissionGroupId;
         }
     }
     if (count($permissionGroupIds) > 0) {
         $usersIds = ContactPermissionGroups::getAllContactsIdsByPermissionGroupIds($permissionGroupIds);
         foreach ($usersIds as $us_id) {
             $user = Contacts::findById($us_id);
             ContactMemberCaches::updateContactMemberCache($user, $member->getId());
         }
     } else {
         //update this member for all user in cache
         $contacts = Contacts::getAllUsers();
         foreach ($contacts as $contact) {
             ContactMemberCaches::updateContactMemberCache($contact, $member->getId());
         }
     }
 }
 /**
  * Return user object
  *
  * @param void
  * @return Contact
  */
 function getUser()
 {
     if (is_null($this->user)) {
         $this->user = Contacts::findById($this->getContactId());
     }
     return $this->user;
 }
 /**
  * Return parent user
  *
  * @param void
  * @return User
  */
 function getUser()
 {
     if (is_null($this->contact)) {
         $this->contact = Contacts::findById($this->getContactId());
     }
     // if
     return $this->contact;
 }
Пример #5
0
 function getUserName()
 {
     $user = Contacts::findById($this->getCreatedById());
     if ($user instanceof Contact) {
         return $user->getUsername();
     } else {
         return null;
     }
 }
Пример #6
0
	function getArrayInfo($include_trash_info = false, $include_archive_info = false) {
		if ($this->getCreatedOn()){
			$dateCreated = $this->getCreatedOn()->isToday() ? lang('today') ." ". format_time($this->getCreatedOn()) : format_datetime($this->getCreatedOn());
		}
		if ($this->getUpdatedOn()){
			$dateUpdated = $this->getUpdatedOn()->isToday() ? lang('today') ." ". format_time($this->getUpdatedOn()) : format_datetime($this->getUpdatedOn());
		}
		$info = array(
			'object_id' => $this->getId(),
			'ot_id' => $this->getObjectTypeId(),
			'name' => $this->getName(),
			'type' => $this->getObjectTypeName(),
			'icon' => $this->getType()->getIconClass(),
			'createdBy' => $this->getCreatedByDisplayName(),
			'createdById' => $this->getCreatedById(),
			'dateCreated' => $dateCreated,
			'updatedBy' => $this->getUpdatedByDisplayName(),
			'updatedById' => $this->getUpdatedById(),
			'dateUpdated' => $dateUpdated,
			'url' => $this->getViewUrl()
		);
		
		if ($include_trash_info) {
			$dateTrashed = $this->getTrashedOn() instanceof DateTimeValue ? ($this->getTrashedOn()->isToday() ? format_time($this->getTrashedOn()) : format_datetime($this->getTrashedOn())) : lang('n/a');
			$info['deletedBy'] = $this->getTrashedByDisplayName();
			$info['deletedById'] = $this->getColumnValue('trashed_by_id');
			$info['dateDeleted'] = $dateTrashed;
		}
		if ($include_archive_info) {
			$dateArchived = $this->getArchivedOn() instanceof DateTimeValue ? ($this->getArchivedOn()->isToday() ? format_time($this->getArchivedOn()) : format_datetime($this->getArchivedOn())) : lang('n/a');
			$archived_by = Contacts::findById($this->getArchivedById());
			$info['archivedBy'] = $archived_by instanceof Contact ? $archived_by->getObjectName() : lang('n/a');
			$info['archivedById'] = $this->getArchivedById();
			$info['dateArchived'] = $dateArchived;
		}
		
		return $info;
	}
Пример #7
0
 function search_permission_group()
 {
     $name = trim(array_var($_REQUEST, 'query', ''));
     $start = array_var($_REQUEST, 'start', 0);
     $orig_limit = array_var($_REQUEST, 'limit');
     $limit = $orig_limit + 1;
     $query_name = "";
     if (strlen($name) > 0) {
         $query_name = "AND (c.first_name LIKE '%{$name}%' OR c.surname LIKE '%{$name}%' OR pg.name LIKE '%{$name}%')";
     }
     // query for permission groups
     $sql = "SELECT * FROM " . TABLE_PREFIX . "permission_groups pg LEFT JOIN " . TABLE_PREFIX . "contacts c ON pg.id=c.permission_group_id\r\n\t\t\tWHERE pg.type IN ('permission_groups', 'user_groups') AND (c.user_type IS NULL OR c.user_type >= " . logged_user()->getUserType() . ") {$query_name}\r\n\t\t\tORDER BY c.first_name, c.surname, pg.name\r\n\t\t\tLIMIT {$start}, {$limit}";
     $rows = DB::executeAll($sql);
     if (!is_array($rows)) {
         $rows = array();
     }
     // show more
     $show_more = false;
     if (count($rows) > $orig_limit) {
         array_pop($rows);
         $show_more = true;
     }
     if ($show_more) {
         ajx_extra_data(array('show_more' => $show_more));
     }
     $tmp_companies = array();
     $tmp_roles = array();
     $permission_groups = array();
     foreach ($rows as $pg_data) {
         // basic data
         $data = array('pg_id' => $pg_data['id'], 'type' => $pg_data['type'] == 'permission_groups' ? 'user' : 'group', 'iconCls' => '', 'name' => is_null($pg_data['first_name']) && is_null($pg_data['surname']) ? $pg_data['name'] : trim($pg_data['first_name'] . ' ' . $pg_data['surname']));
         // company name
         $comp_id = array_var($pg_data, 'company_id');
         if ($comp_id > 0) {
             if (!isset($tmp_companies[$comp_id])) {
                 $tmp_companies[$comp_id] = Contacts::findById($comp_id);
             }
             $c = array_var($tmp_companies, $comp_id);
             if ($c instanceof Contact) {
                 $data['company_name'] = trim($c->getObjectName());
             }
         }
         // picture
         if ($pg_data['type'] == 'permission_groups') {
             $data['user_id'] = array_var($pg_data, 'object_id');
             if (array_var($pg_data, 'picture_file') != '') {
                 $data['picture_url'] = get_url('files', 'get_public_file', array('id' => array_var($pg_data, 'picture_file')));
             }
         }
         // user type
         $user_type_id = array_var($pg_data, 'user_type');
         if ($user_type_id > 0) {
             if (!isset($tmp_roles[$user_type_id])) {
                 $tmp_roles[$user_type_id] = PermissionGroups::findById($user_type_id);
             }
             $rol = array_var($tmp_roles, $user_type_id);
             if ($rol instanceof PermissionGroup) {
                 $data['role'] = trim($rol->getName());
                 if (in_array($rol->getName(), array('Guest', 'Guest Customer'))) {
                     $data['is_guest'] = '1';
                 }
             }
         }
         $permission_groups[] = $data;
     }
     $row = "search-result-row-medium";
     ajx_extra_data(array('row_class' => $row));
     ajx_extra_data(array('permission_groups' => $permission_groups));
     ajx_current("empty");
 }
Пример #8
0
 /** Send event notification to the list of users ($people)
  *
  * @param ProjectEvent $event Event
  * @param array $people
  * @return boolean
  * @throws NotifierConnectionError
  */
 static function notifEventAssistance(ProjectEvent $event, EventInvitation $invitation, $from_user, $invs = null)
 {
     if (!$event instanceof ProjectEvent || !$invitation instanceof EventInvitation || !$event->getCreatedBy() instanceof Contacts || !$from_user instanceof Contact) {
         return;
     }
     tpl_assign('event', $event);
     tpl_assign('invitation', $invitation);
     tpl_assign('from_user', $from_user);
     $assist = array();
     $not_assist = array();
     $pending = array();
     if (isset($invs)) {
         foreach ($invs as $inv) {
             if ($inv->getUserId() == $from_user->getId()) {
                 continue;
             }
             $decision = $inv->getInvitationState();
             $user_name = Contacts::findById($inv->getUserId())->getObjectName();
             if ($decision == 1) {
                 $assist[] = $user_name;
             } else {
                 if ($decision == 2) {
                     $not_assist[] = $user_name;
                 } else {
                     $pending[] = $user_name;
                 }
             }
         }
     }
     tpl_assign('assist', $assist);
     tpl_assign('not_assist', $not_assist);
     tpl_assign('pending', $pending);
     $people = array($event->getCreatedBy());
     $recepients = array();
     foreach ($people as $user) {
         $locale = $user->getLocale();
         Localization::instance()->loadSettings($locale, ROOT . '/language');
         $date = Localization::instance()->formatDescriptiveDate($event->getStart(), $user->getTimezone());
         if ($event->getTypeId() != 2) {
             $date .= " " . Localization::instance()->formatTime($event->getStart(), $user->getTimezone());
         }
         tpl_assign('date', $date);
         $toemail = $user->getEmailAddress();
         if (!$toemail) {
             continue;
         }
         self::queueEmail(array(self::prepareEmailAddress($toemail, $user->getObjectName())), null, null, self::prepareEmailAddress($from_user->getEmailAddress(), $from_user->getObjectName()), lang('event invitation response') . ': ' . $event->getSubject(), tpl_fetch(get_template_path('event_inv_response_notif', 'notifier')));
         // send
     }
     // foreach
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
 }
Пример #9
0
 function getActivityData()
 {
     $user = Contacts::findById($this->getCreatedById());
     $object = Objects::findObject($this->getRelObjectId());
     if (!$user) {
         return false;
     }
     $icon_class = "";
     if ($object instanceof ProjectFile) {
         $path = explode("-", str_replace(".", "_", str_replace("/", "-", $object->getTypeString())));
         $acc = "";
         foreach ($path as $p) {
             $acc .= $p;
             $icon_class .= ' ico-' . $acc;
             $acc .= "-";
         }
     }
     // Build data depending on type
     if ($object) {
         if ($object instanceof Contact && $object->isUser()) {
             $type = "user";
         } else {
             $type = $object->getObjectTypeName();
         }
         $object_link = '<a style="font-weight:bold" href="' . $object->getObjectUrl() . '">&nbsp;' . '<span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $type . $icon_class . '"/>' . clean($object->getObjectName()) . '</a>';
     } else {
         $object_link = clean($this->getObjectName()) . '&nbsp;' . lang('object is deleted');
     }
     switch ($this->getAction()) {
         case ApplicationLogs::ACTION_EDIT:
         case ApplicationLogs::ACTION_ADD:
         case ApplicationLogs::ACTION_DELETE:
         case ApplicationLogs::ACTION_TRASH:
         case ApplicationLogs::ACTION_UNTRASH:
         case ApplicationLogs::ACTION_OPEN:
         case ApplicationLogs::ACTION_CLOSE:
         case ApplicationLogs::ACTION_ARCHIVE:
         case ApplicationLogs::ACTION_UNARCHIVE:
         case ApplicationLogs::ACTION_READ:
         case ApplicationLogs::ACTION_DOWNLOAD:
         case ApplicationLogs::ACTION_CHECKIN:
         case ApplicationLogs::ACTION_CHECKOUT:
             if ($object) {
                 return lang('activity ' . $this->getAction(), lang('the ' . $type), $user->getDisplayName(), $object_link);
             }
         case ApplicationLogs::ACTION_SUBSCRIBE:
         case ApplicationLogs::ACTION_UNSUBSCRIBE:
             $user_ids = explode(",", $this->getLogData());
             if (count($user_ids) < 8) {
                 $users_str = "";
                 foreach ($user_ids as $usid) {
                     $su = Contacts::findById($usid);
                     if ($su instanceof Contact) {
                         $users_str .= '<a style="font-weight:bold" href="' . $su->getObjectUrl() . '">&nbsp;<span style="padding: 0 0 3px 18px;" class="db-ico ico-unknown ico-user"/>' . clean($su->getObjectName()) . '</a>, ';
                     }
                 }
                 if (count($user_ids) == 1) {
                     $users_text = substr(trim($users_str), 0, -1);
                 } else {
                     $users_text = lang('x users', count($user_ids), ": {$users_str}");
                 }
             } else {
                 $users_text = lang('x users', count($user_ids), "");
             }
             if ($object) {
                 return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $users_text);
             }
         case ApplicationLogs::ACTION_COMMENT:
             if ($object) {
                 return lang('activity ' . $this->getAction(), lang('the ' . $object->getRelObject()->getObjectTypeName()), $user->getDisplayName(), $object_link, $this->getLogData());
             }
         case ApplicationLogs::ACTION_LINK:
         case ApplicationLogs::ACTION_UNLINK:
             $exploded = explode(":", $this->getLogData());
             $linked_object = Objects::findObject($exploded[1]);
             if ($linked_object instanceof ApplicationDataObject) {
                 $icon_class = "";
                 if ($linked_object instanceof ProjectFile) {
                     $path = explode("-", str_replace(".", "_", str_replace("/", "-", $linked_object->getTypeString())));
                     $acc = "";
                     foreach ($path as $p) {
                         $acc .= $p;
                         $icon_class .= ' ico-' . $acc;
                         $acc .= "-";
                     }
                 }
                 $linked_object_link = '<a style="font-weight:bold" href="' . $linked_object->getObjectUrl() . '">&nbsp;<span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $linked_object->getObjectTypeName() . $icon_class . '"/>' . clean($linked_object->getObjectName()) . '</a>';
             } else {
                 $linked_object_link = '';
             }
             if ($object) {
                 return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $linked_object instanceof ApplicationDataObject ? lang('the ' . $linked_object->getObjectTypeName()) : '', $linked_object_link);
             }
         case ApplicationLogs::ACTION_LOGIN:
         case ApplicationLogs::ACTION_LOGOUT:
             return lang('activity ' . $this->getAction(), $user->getDisplayName());
             /*FIXME when D&D is implemented case ApplicationLogs::ACTION_MOVE :
             			$exploded = explode(";", $this->getLogData());
             			$to_str = "";
             			$from_str = "";
             			foreach ($exploded as $str) {
             				if (str_starts_with($str, "from:")) {
             					$wsids_csv = str_replace("from:", "", $str);
             					$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
             					if (is_array($wsids) && count($wsids) > 0) {
             						$from_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
             					}
             				} else if (str_starts_with($str, "to:")) {
             					$wsids_csv = str_replace("to:", "", $str);
             					$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
             					if (is_array($wsids) && count($wsids) > 0) {
             						$to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
             					}						
             				}
             			}
             			if($object){
             				if ($from_str != "" && $to_str != "") {						
             					return lang('activity ' . $this->getAction() . ' from to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str, $to_str);
             				} else if ($from_str != "") {
             					return lang('activity ' . $this->getAction() . ' from', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str);
             				} else if ($to_str != "") {
             					return lang('activity ' . $this->getAction() . ' to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str);
             				} else {
             					return lang('activity ' . $this->getAction() . ' no ws', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link);
             				}
             			}		
             		case ApplicationLogs::ACTION_COPY :				
             			$to_str = "";
             			$wsids_csv = str_replace("to:", "", $this->getLogData());
             			$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
             			if (is_array($wsids) && count($wsids) > 0) {
             				$to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
             			}
             			if($object){
             				if ($to_str != "") {
             					return lang('activity ' . $this->getAction() . ' to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str);
             				} 
             			}else{
             				if ($to_str != "") {
             					return lang('activity ' . $this->getAction() . ' to', lang('the '.$this->getRelObjectManager()), $user->getDisplayName(), $object_link, $to_str);
             				}
             			}	*/
         /*FIXME when D&D is implemented case ApplicationLogs::ACTION_MOVE :
         			$exploded = explode(";", $this->getLogData());
         			$to_str = "";
         			$from_str = "";
         			foreach ($exploded as $str) {
         				if (str_starts_with($str, "from:")) {
         					$wsids_csv = str_replace("from:", "", $str);
         					$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
         					if (is_array($wsids) && count($wsids) > 0) {
         						$from_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
         					}
         				} else if (str_starts_with($str, "to:")) {
         					$wsids_csv = str_replace("to:", "", $str);
         					$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
         					if (is_array($wsids) && count($wsids) > 0) {
         						$to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
         					}						
         				}
         			}
         			if($object){
         				if ($from_str != "" && $to_str != "") {						
         					return lang('activity ' . $this->getAction() . ' from to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str, $to_str);
         				} else if ($from_str != "") {
         					return lang('activity ' . $this->getAction() . ' from', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str);
         				} else if ($to_str != "") {
         					return lang('activity ' . $this->getAction() . ' to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str);
         				} else {
         					return lang('activity ' . $this->getAction() . ' no ws', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link);
         				}
         			}		
         		case ApplicationLogs::ACTION_COPY :				
         			$to_str = "";
         			$wsids_csv = str_replace("to:", "", $this->getLogData());
         			$wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv));
         			if (is_array($wsids) && count($wsids) > 0) {
         				$to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>';
         			}
         			if($object){
         				if ($to_str != "") {
         					return lang('activity ' . $this->getAction() . ' to', lang('the '.$object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str);
         				} 
         			}else{
         				if ($to_str != "") {
         					return lang('activity ' . $this->getAction() . ' to', lang('the '.$this->getRelObjectManager()), $user->getDisplayName(), $object_link, $to_str);
         				}
         			}	*/
         default:
             return false;
     }
     return false;
 }
Пример #10
0
		if(!isset($grouped[$user->getCompanyId()]) || !is_array($grouped[$user->getCompanyId()])) {
			$grouped[$user->getCompanyId()] = array();
		}
		$grouped[$user->getCompanyId()][] = $user;
	}
	$companyUsers = $grouped;
?>
<div id="<?php echo $genid ?>notify_companies">

<?php foreach($companyUsers as $companyId => $users) { ?>

<div id="<?php echo $companyId?>" class="company-users" <?php echo is_array($users) == true? 'style ="margin-bottom: 10px;"' : '' ?> >

	<?php if(is_array($users) && count($users)) { ?>
		<div onclick="og.subscribeCompany(this)" class="container-div company-name<?php echo $allChecked ? ' checked' : '' ?>" onmouseout="og.rollOut(this,true)" onmouseover="og.rollOver(this)">
		<?php $theCompany = Contacts::findById($companyId) ?>
			<label for="<?php echo $genid ?>notifyCompany<?php echo ($theCompany instanceof Contact ? $theCompany->getId() : "0") ?>" style="background: url('<?php echo ($theCompany instanceof Contact ? $theCompany->getPictureUrl() : "#") ?>') no-repeat;"><?php echo ($theCompany instanceof Contact ? clean($theCompany->getFirstName()) : lang('without company')) ?></label><br/>
		</div>
		<div style="padding-left:10px;">
		<?php foreach($users as $user) { ?>
				<?php
					$checked = in_array($user->getId(), $subscriberIds);
				?>
				<div id="div<?php echo $genid ?>inviteUser<?php echo $user->getId() ?>" class="container-div <?php echo $checked==true? 'checked-user':'******' ?>" onmouseout="og.rollOut(this,false <?php echo $checked==true? ',true':',false' ?>)" onmouseover="og.rollOver(this)" onclick="og.checkUser(this)">
					<input <?php echo $checked? 'checked="checked"':'' ?> id="<?php echo $genid ?>inviteUser<?php echo $user->getId()?>" type="checkbox" style="display:none" name="<?php echo 'subscribers[user_'.$user->getId() .']' ?>" value="checked" />
					<label for="<?php echo $genid ?>notifyUser<?php echo $user->getId() ?>" style=" width: 120px; overflow:hidden; background:url('<?php echo $user->getPictureUrl() ?>') no-repeat;">
						<span class="ico-user link-ico"><?php echo clean($user->getObjectName()) ?></span>
						<br>
						<span style="color:#888888;font-size:90%;font-weight:normal;"> <?php echo $user->getEmailAddress()  ?> </span>
					</label>
					
Пример #11
0
	function get_company_data(){
		ajx_current("empty");
		$id = array_var($_GET, 'id');
		$company = Contacts::findById($id);
		
		if ($company){
			$address = $company->getAddress('work');
			$street = "";
			$city = "";
			$state = "";
			$zipcode = "";
			$country = "";
			if($address){
				$street = $address->getStreet();
				$city = $address->getCity();
				$state = $address->getState();
				$zipcode = $address->getZipCode();
				$country = $address->getCountry();
			}
			ajx_extra_data(array(
				"id" => $company->getObjectId(),
				"address" => $street,
				"state" => $state,
				"city" => $city,
				"country" => $country,
				"zipcode" => $zipcode,
				"webpage" => $company->getWebpageURL('work'),
				"phoneNumber" => $company->getPhoneNumber('work', true),
				"faxNumber" => $company->getPhoneNumber('fax', true)
			));
		} else {
			ajx_extra_data(array(
				"id" => 0
			));
		}
	}
Пример #12
0
         }
     }
     //if
 }
 // if
 $otherInvitationsTable = '';
 if (!$event->isNew()) {
     $otherInvitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $event->getId()));
     if (isset($otherInvitations) && is_array($otherInvitations)) {
         $otherInvitationsTable .= '<div class="coInputMainBlock adminMainBlock" style="width:70%;">';
         $otherInvitationsTable .= '<table style="width:100%;"><col width="50%" /><col width="50%" />';
         $otherInvitationsTable .= '<tr><th><b>' . lang('name') . '</b></th><th><b>' . lang('participate') . '</b></th></tr>';
         $isAlt = false;
         $cant = 0;
         foreach ($otherInvitations as $inv) {
             $inv_user = Contacts::findById($inv->getContactId());
             if ($inv_user instanceof Contact) {
                 if (can_access($inv_user, $event->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                     if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_update_other_users_invitations')) {
                         // only show status
                         $state_desc = lang('pending response');
                         if ($inv->getInvitationState() == 1) {
                             $state_desc = lang('yes');
                         } else {
                             if ($inv->getInvitationState() == 2) {
                                 $state_desc = lang('no');
                             } else {
                                 if ($inv->getInvitationState() == 3) {
                                     $state_desc = lang('maybe');
                                 }
                             }
Пример #13
0
 /**
  * Return contact
  *
  * @access public
  * @param void
  * @return Contact
  */
 function getContact()
 {
     return Contacts::findById($this->getContactId());
 }
Пример #14
0
	function list_files() {
		
		ajx_current("empty");
		// get query parameters 
		$start = (integer)array_var($_GET,'start');
		$limit = (integer)array_var($_GET,'limit');
		if (! $start) {
			$start = 0;
		}
		if (! $limit) {
			$limit = config_option('files_per_page');
		}
		$order = array_var($_GET,'sort');
		$order_dir = array_var($_GET,'dir');
		$page = (integer) ($start / $limit)+1;
		$hide_private = !logged_user()->isMemberOfOwnerCompany();
		$type = array_var($_GET,'type');
		$user = array_var($_GET,'user');

		// if there's an action to execute, do so 
		if (array_var($_GET, 'action') == 'delete') {
			$ids = explode(',', array_var($_GET, 'objects'));
			$succ = 0; $err = 0;
			foreach ($ids as $id) {
				$file = ProjectFiles::findById($id);
				if (isset($file) && $file->canDelete(logged_user())) {
					try{
						DB::beginWork();
						$file->trash();
						ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH);
						DB::commit();
						$succ++;
					} catch(Exception $e){
						DB::rollback();
						$err++;
					}
				} else {
					$err++;
				}
			}
			if ($succ > 0) {
				flash_success(lang("success delete files", $succ));
			} else {
				flash_error(lang("error delete files", $err));
			}

		} else if (array_var($_GET, 'action') == 'markasread') {
			$ids = explode(',', array_var($_GET, 'objects'));
			$succ = 0; $err = 0;
				foreach ($ids as $id) {
				$file = ProjectFiles::findById($id);
					try {
						$file->setIsRead(logged_user()->getId(),true);
						$succ++;
						
					} catch(Exception $e) {
						$err ++;
					} // try
				}//for
			if ($succ <= 0) {
				flash_error(lang("error markasread files", $err));
			}
		}else if (array_var($_GET, 'action') == 'markasunread') {
			$ids = explode(',', array_var($_GET, 'objects'));
			$succ = 0; $err = 0;
				foreach ($ids as $id) {
				$file = ProjectFiles::findById($id);
					try {
						$file->setIsRead(logged_user()->getId(),false);
						$succ++;

					} catch(Exception $e) {
						$err ++;
					} // try
				}//for
			if ($succ <= 0) {
				flash_error(lang("error markasunread files", $err));
			}
		}
		 else if (array_var($_GET, 'action') == 'zip_add') {
			$this->zip_add();
		} else if (array_var($_GET, 'action') == 'archive') {
			$ids = explode(',', array_var($_GET, 'ids'));
			$succ = 0; $err = 0;
			foreach ($ids as $id) {
				$file = ProjectFiles::findById($id);
				if (isset($file) && $file->canEdit(logged_user())) {
					try{
						DB::beginWork();
						$file->archive();
						ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE);
						DB::commit();
						$succ++;
					} catch(Exception $e){
						DB::rollback();
						$err++;
					}
				} else {
					$err++;
				}
			}
			if ($succ > 0) {
				flash_success(lang("success archive objects", $succ));
			} else {
				flash_error(lang("error archive objects", $err));
			}
		}
		
		Hook::fire('classify_action', null, $ret);		
		$join_params = null;
		
		if ($order == ProjectFiles::ORDER_BY_POSTTIME) {
			$order = '`created_on`';
		} else if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) {
			$order = '`updated_on`';
		} else if ($order == ProjectFiles::ORDER_BY_SIZE) {
			$order = '`jt`.`filesize`';
			$join_params = array(
				'table' => ProjectFileRevisions::instance()->getTableName(),
				'jt_field' => 'object_id',
				'j_sub_q' => "SELECT max(`x`.`object_id`) FROM ".ProjectFileRevisions::instance()->getTableName()." `x` WHERE `x`.`file_id` = `e`.`object_id`"
			);
		} else {
			$order = '`name`';
		} // if
		
		$extra_conditions = $hide_private ? 'AND `is_visible` = 1' : '';
		
		$context = active_context();
		$objects = ProjectFiles::instance()->listing(array(
			"order"=>$order,
			"order_dir" => $order_dir,
			"extra_conditions"=> $extra_conditions,
			"join_params"=> $join_params,
			"start"=> $start,
			"limit"=> $limit
		));
		
		
		$custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId());
		
		// prepare response object 
		$listing = array(
			"totalCount" => $objects->total,
			"start" => $start,
			"objType" => ProjectFiles::instance()->getObjectTypeId(),
			"files" => array(),
		);
		
		if (is_array($objects->objects)) {
			$index = 0;
			$ids = array();
			foreach ($objects->objects as $o) {
				$coName = "";
				$coId = $o->getCheckedOutById();
				if ($coId != 0) {
					if ($coId == logged_user()->getId()) {
						$coName = "self";
					} else {
						$coUser = Contacts::findById($coId);
						if ($coUser instanceof Contact) {
							$coName = $coUser->getUsername();
						} else {
							$coName = "";
						}
					}
				}

				if ($o->isMP3()) {
					$songname = $o->getProperty("songname");
					$artist = $o->getProperty("songartist");
					$album = $o->getProperty("songalbum");
					$track = $o->getProperty("songtrack");
					$year = $o->getProperty("songyear");
					$duration = $o->getProperty("songduration");
					$songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId()));
				} else {
					$songInfo = array();
				}
				
				$ids[] = $o->getId();
				$values = array(
					"id" => $o->getId(),
					"ix" => $index++,
					"object_id" => $o->getId(),
					"ot_id" => $o->getObjectTypeId(),
					"name" => $o->getObjectName(),
					"type" => $o->getTypeString(),
					"mimeType" => $o->getTypeString(),
					"createdBy" => clean($o->getCreatedByDisplayName()),
					"createdById" => $o->getCreatedById(),
					"dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? ($o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn())) : '',
					"dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0,
					"updatedBy" => clean($o->getUpdatedByDisplayName()),
					"updatedById" => $o->getUpdatedById(),
					"dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? ($o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn())) : '',
					"dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0,
					"icon" => $o->getTypeIconUrl(),
					"size" => format_filesize($o->getFileSize()),
					"url" => $o->getOpenUrl(),
					"manager" => get_class($o->manager()),
					"checkedOutByName" => $coName,
					"checkedOutById" => $coId,
					"isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()),
					"modifyUrl" => $o->getModifyUrl(),
					"songInfo" => $songInfo,
					"ftype" => $o->getType(),
					"url" => $o->getUrl(),
					"memPath" => json_encode($o->getMembersToDisplayPath()),
				);
				if ($o->isMP3()) {
					$values['isMP3'] = true;
				}
				Hook::fire('add_classification_value', $o, $values);
				
				foreach ($custom_properties as $cp) {
					$cp_value = CustomPropertyValues::getCustomPropertyValue($o->getId(), $cp->getId());
					$values['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : '';
				}
				
				$listing["files"][] = $values;
			}
			
			$read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId());
			foreach($listing["files"] as &$data) {
				$data['isRead'] = isset($read_objects[$data['object_id']]);
			}
			
			ajx_extra_data($listing);
			tpl_assign("listing", $listing);
		}else{
			throw new Error("Not array", $code);			
		}
	}
Пример #15
0
/**
 * 
 * After editing permissions refresh associations and object_members for the contact owner of the permission_group modified
 * @param $pg_id Permission group id
 * @param $ignored Ignored
 */
function core_dimensions_after_save_contact_permissions($pg_id, &$ignored) {
	$pg = PermissionGroups::findById($pg_id);
	if ($pg instanceof PermissionGroup && $pg->getContactId() > 0 && $pg->getType() == 'permission_groups') {
		$user = Contacts::findById($pg->getContactId());
		if (!$user instanceof Contact || !$user->isUser()) return;
		
		$member_ids = array();
		$cmps = ContactMemberPermissions::instance()->findAll(array("conditions" => "permission_group_id = ".$pg_id));
		foreach ($cmps as $cmp) {
			$member_ids[$cmp->getMemberId()] = $cmp->getMemberId();
		}
		if (count($member_ids) == 0) return;
		
		$members = Members::findAll(array('conditions' => 'id IN ('.implode(',', $member_ids).')'));
		$persons_dim = Dimensions::findByCode("feng_persons");
		$user_member = Members::findOneByObjectId($user->getId(), $persons_dim->getId());
		
		$affected_dimensions = core_dim_create_member_associations($user, $user_member, $members);
		
		// remove from all members of the affected dimensions
		if (count($affected_dimensions) > 0) {
			$affected_member_ids = Members::findAll(array('id' => true, 'conditions' => 'dimension_id IN ('.implode(',', $affected_dimensions).')'));
			if (count($affected_member_ids) > 0) {
				ObjectMembers::removeObjectFromMembers($user, logged_user(), $members, $affected_member_ids);
			}
		}		
		// add user content object to associated members
		$obj_controller = new ObjectController();
		ObjectMembers::addObjectToMembers($user->getId(), $members);
		$user->addToSharingTable();
	}
}
Пример #16
0
 function reset_password()
 {
     $tok = array_var($_GET, 't');
     $uid = array_var($_GET, 'uid');
     $type_notifier = array_var($_GET, 'type_notifier');
     if (!$tok || !$uid) {
         flash_error(lang('invalid parameters'));
         $this->redirectTo('access', 'login');
     }
     $user = Contacts::findById($uid);
     if (!($user instanceof Contact && $user->isUser()) || $user->getDisabled()) {
         flash_error(lang('user dnx'));
         $this->redirectTo('access', 'login');
     }
     $stok = user_config_option('reset_password', null, $user->getId());
     if (!$stok) {
         flash_error(lang('reset password expired', lang('forgot password')));
         $this->redirectTo('access', 'login');
     }
     $split = explode(";", $stok);
     if (count($split) < 2) {
         flash_error(lang('reset password expired', lang('forgot password')));
         $this->redirectTo('access', 'login');
     }
     $token = $split[0];
     $timestamp = $split[1];
     if ($timestamp < time()) {
         set_user_config_option('reset_password', '', $user->getId());
         flash_error(lang('reset password expired', lang('forgot password')));
         $this->redirectTo('access', 'login');
     }
     if ($token != $tok) {
         flash_error(lang('reset password expired', lang('forgot password')));
         $this->redirectTo('access', 'login');
     }
     tpl_assign('token', $token);
     tpl_assign('user', $user);
     tpl_assign('type_notifier', $type_notifier);
     $new_password = array_var($_POST, 'new_password');
     if ($new_password) {
         $repeat_password = array_var($_POST, 'repeat_password');
         if ($new_password != $repeat_password) {
             flash_error(lang('passwords dont match'));
             return;
         }
         try {
             $user_password = new ContactPassword();
             $user_password->setContactId($user->getId());
             $user_password->password_temp = $new_password;
             $user_password->setPasswordDate(DateTimeValueLib::now());
             $user_password->setPassword(cp_encrypt($new_password, $user_password->getPasswordDate()->getTimestamp()));
             $user_password->save();
             $user->setPassword($new_password);
             $user->setUpdatedOn(DateTimeValueLib::now());
             $user->save();
             set_user_config_option('reset_password', '', $user->getId());
             flash_success(lang('success reset password'));
             CompanyWebsite::instance()->logUserOut();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             flash_error($e->getMessage());
         }
     }
 }
Пример #17
0
<?php    
    $options = explode(",",user_config_option("filters_dashboard"));
    
    $activities =  ApplicationLogs::getLastActivities();
    $limit = $options[2];
    $acts = array();
    $acts['data'] = array();
    foreach($activities as $activity){
        $user = Contacts::findById($activity->getCreatedById());
        if ($activity->getLogData() == 'member deleted') {
        	$object = Members::findById($activity->getRelObjectId());
        	$member_deleted = true;
        } else {
        	$object = Objects::findObject($activity->getRelObjectId());
        }
        
        if($object || $member_deleted){
            $key = $activity->getRelObjectId() . "-" . $activity->getCreatedById();

            if(count($acts['data']) < ($limit*2)){
                if(!array_key_exists($key, $acts['data'])){
                    $acts['data'][$key] = $object;
                    $acts['created_by'][$key] = $user;
                    $acts['act_data'][$key] = $activity->getActivityDataView($user,$object);
                    $acts['date'][$key] = $activity->getCreatedOn() instanceof DateTimeValue ? friendly_date($activity->getCreatedOn()) : lang('n/a');
                }else{
                    $acts['data'][$key] = $object;
                    $acts['created_by'][$key] = $user;
                    $acts['act_data'][$key] = $activity->getActivityDataView($user,$object,true);
                    $acts['date'][$key] = $activity->getCreatedOn() instanceof DateTimeValue ? friendly_date($activity->getCreatedOn()) : lang('n/a');
                }            
 /**
  * Return user who made this acction
  *
  * @access public
  * @param void
  * @return Contact
  */
 function getTakenBy()
 {
     return Contacts::findById($this->getTakenById());
 }
Пример #19
0
/**
 * Render assign to SELECT
 * @param string $list_name Name of the select control
 * @param Project $project Selected project, if NULL active project will be used
 * @param integer $selected ID of selected user
 * @param array $attributes Array of select box attributes, if needed
 * @return null
 */ 
function filter_assigned_to_select_box($list_name, $project = null, $selected = null, $attributes = null) {
	$grouped_users = Contacts::getGroupedByCompany(false);
	$options = array(option_tag(lang('anyone'), '0:0'),option_tag(lang('unassigned'), '-1:-1', '-1:-1' == $selected ? array('selected' => 'selected') : null));
	
	if(is_array($grouped_users) && count($grouped_users)) {
		foreach($grouped_users as $company_id => $users) {
			$company = Contacts::findById($company_id);
			if(!($company instanceof Contact)) {
				continue;
			} // if

			$options[] = option_tag('--', '0:0'); // separator

			$option_attributes = $company->getId() . ':0' == $selected ? array('selected' => 'selected') : null;
			$options[] = option_tag($company->getName(), $company_id . ':0', $option_attributes);

			if(is_array($users)) {
				foreach($users as $user) {
					$option_attributes = $company_id . ':' . $user->getId() == $selected ? array('selected' => 'selected') : null;
					$options[] = option_tag($user->getObjectName() . ' : ' . $company->getObjectName() , $company_id . ':' . $user->getId(), $option_attributes);
				} // foreach
			} // if

		} // foreach
	} // if

	return select_box($list_name, $options, $attributes);
} // assign_to_select_box
Пример #20
0
 function restore_user()
 {
     $user = Contacts::findById(get_id());
     if (!($user instanceof Contact && $user->isUser())) {
         flash_error(lang('user dnx'));
         ajx_current("empty");
         return;
     }
     if (!$user->canDelete(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     try {
         DB::beginWork();
         $user->setDisabled(false);
         $user->unarchive();
         ApplicationLogs::createLog($user, ApplicationLogs::ACTION_UNTRASH);
         $ret = null;
         Hook::fire("user_restored", $user, $ret);
         DB::commit();
         flash_success('success delete user');
         ajx_current("reload");
     } catch (Exception $e) {
         flash_error($e->getMessage());
         DB::rollback();
         ajx_current("empty");
     }
 }
 /**
  * Edit project
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_project');
     $project = Projects::findById(get_id());
     if (!$project instanceof Project) {
         flash_error(lang('project dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$project->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $project_data = array_var($_POST, 'project');
     if (!is_array($project_data)) {
         $project_data = array('name' => $project->getName(), 'description' => $project->getDescription(), 'show_description_in_overview' => $project->getShowDescriptionInOverview(), 'color' => 0);
         // array
     }
     // if
     $projects = logged_user()->getActiveProjects();
     tpl_assign('project', $project);
     tpl_assign('projects', $projects);
     tpl_assign('project_data', $project_data);
     tpl_assign('billing_amounts', $project->getBillingAmounts());
     tpl_assign('subject_matter_experts', ProjectContacts::getContactsByProject($project));
     if (is_array(array_var($_POST, 'project'))) {
         if (array_var($project_data, 'parent_id') == $project->getId()) {
             flash_error(lang("workspace own parent error"));
             ajx_current("empty");
             return;
         }
         if (!isset($project_data['parent_id'])) {
             $project_data['parent_id'] = $project->getParentId();
         }
         $project->setFromAttributes($project_data);
         try {
             DB::beginWork();
             if (array_var($project_data, 'parent_id') != $project->getParentId()) {
                 if ($project->getParentWorkspace() instanceof Project && !logged_user()->isProjectUser($project->getParentWorkspace())) {
                     flash_error(lang('no access permissions'));
                     ajx_current("empty");
                     return;
                 }
                 // if
                 $parent = Projects::findById(array_var($project_data, 'parent_id'));
                 if ($parent) {
                     if (!$project->canSetAsParentWorkspace($parent)) {
                         flash_error(lang('error cannot set workspace as parent', $parent->getName()));
                         ajx_current("empty");
                         return;
                     }
                 }
                 $project->setParentWorkspace($parent);
             }
             $project->save();
             /* Billing */
             WorkspaceBillings::clearByProject($project);
             $billings = array_var($project_data, 'billing', null);
             if ($billings) {
                 foreach ($billings as $billing_id => $billing) {
                     if ($billing['update'] && $billing['value'] && $billing['value'] != 0) {
                         $wb = new WorkspaceBilling();
                         $wb->setProjectId($project->getId());
                         $wb->setBillingId($billing_id);
                         $value = $billing['value'];
                         if (strpos($value, ',') && !strpos($value, '.')) {
                             $value = str_replace(',', '.', $value);
                         }
                         $wb->setValue($value);
                         $wb->save();
                     }
                 }
             }
             /* Project contacts */
             if (can_manage_contacts(logged_user())) {
                 ProjectContacts::clearByProject($project);
                 $contacts = array_var($project_data, 'contacts', null);
                 if ($contacts) {
                     foreach ($contacts as $contact_data) {
                         $contact = Contacts::findById($contact_data['contact_id']);
                         if ($contact instanceof Contact) {
                             $pc = new ProjectContact();
                             $pc->setProjectId($project->getId());
                             $pc->setContactId($contact_data['contact_id']);
                             $pc->setRole($contact_data['role']);
                             $pc->save();
                         }
                     }
                 }
             }
             /* <permissions> */
             $permissions = null;
             $permissionsString = array_var($_POST, 'permissions');
             if ($permissionsString && $permissionsString != '') {
                 $permissions = json_decode($permissionsString);
             }
             if (is_array($permissions) && count($permissions) > 0) {
                 //Clear old modified permissions
                 $ids = array();
                 foreach ($permissions as $perm) {
                     $ids[] = $perm->wsid;
                 }
                 ProjectUsers::clearByProject($project, implode(',', $ids));
                 //Add new permissions
                 //TODO - Make batch update of these permissions
                 foreach ($permissions as $perm) {
                     if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($perm->wsid);
                         $relation->setCheckboxPermissions($perm->pc, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->setRadioPermissions($perm->pr, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->save();
                     }
                     //endif
                     //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created
                 }
                 //end foreach
             }
             // if
             /* </permissions> */
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($project);
             ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_EDIT, false, true);
             DB::commit();
             if (logged_user()->isProjectUser($project)) {
                 $workspace_info = $this->get_workspace_info($project);
                 evt_add("workspace edited", $workspace_info);
             }
             flash_success(lang('success edit project', $project->getName()));
             ajx_current("back");
             return;
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
Пример #22
0
 /**
  * This function will use session ID from session or cookie and if presend log user
  * with that ID. If not it will simply break.
  *
  * When this function uses session ID from cookie the whole process will be treated
  * as new login and users last login time will be set to current time.
  *
  * @access public
  * @param void
  * @return boolean
  */
 private function initLoggedUser()
 {
     //Hack for API Auth & Magic login!
     if (isset($_REQUEST['auth']) && !empty($_REQUEST['auth']) || array_var($_REQUEST, 'm') == "login") {
         if (array_var($_REQUEST, 'm') != "login") {
             $contact = Contacts::findAll(array("conditions" => "`token` = '" . $_REQUEST['auth'] . "'"));
             $contact = $contact[0];
         } else {
             $username = $_REQUEST['username'];
             $password = $_REQUEST['password'];
             if (preg_match(EMAIL_FORMAT, $username)) {
                 $contact = Contacts::getByEmail($username);
             } else {
                 $contact = Contacts::getByUsername($username);
             }
             if ($contact) {
                 if (!$contact->isValidPassword($password)) {
                     die('API Response: Invalid password.');
                 }
             } else {
                 die('API Response: Invalid username.');
             }
         }
         if ($contact instanceof Contact) {
             $this->logUserIn($contact, false);
             if (array_var($_REQUEST, 'm') == "login") {
                 $temp = array('token' => $contact->getToken(), 'username' => $contact->getUsername(), 'user_id' => $contact->getId(), 'company' => owner_company()->getName());
                 echo json_encode($temp);
                 exit;
             }
         } else {
             die('API Response: Invalid authorization code.');
         }
     }
     $user_id = Cookie::getValue('id');
     $twisted_token = Cookie::getValue('token');
     $remember = (bool) Cookie::getValue('remember', false);
     if (empty($user_id) || empty($twisted_token)) {
         return false;
         // we don't have a user
     }
     // if
     $user = Contacts::findById($user_id);
     if (!$user instanceof Contact) {
         return false;
         // failed to find user
     }
     // if
     if (!$user->isValidToken($twisted_token)) {
         return false;
         // failed to validate token
     }
     // if
     $last_act = $user->getLastActivity();
     if ($last_act instanceof DateTimeValue) {
         $session_expires = $last_act->advance(SESSION_LIFETIME, false);
     }
     if (!$last_act instanceof DateTimeValue || $session_expires != null && DateTimeValueLib::now()->getTimestamp() < $session_expires->getTimestamp()) {
         $this->setLoggedUser($user, $remember, true);
     } else {
         $this->logUserIn($user, $remember);
     }
     // if
 }
Пример #23
0
 function getExternalColumnValue($field, $id, $manager = null, $object = null)
 {
     $value = '';
     if ($field == 'user_id' || $field == 'contact_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_contact_id' || $field == 'assigned_by_id' || $field == 'completed_by_id' || $field == 'approved_by_id') {
         $contact = Contacts::findById($id);
         if ($contact instanceof Contact) {
             $value = $contact->getObjectName();
         }
     } else {
         if ($field == 'milestone_id') {
             $milestone = ProjectMilestones::findById($id);
             if ($milestone instanceof ProjectMilestone) {
                 $value = $milestone->getObjectName();
             }
         } else {
             if ($field == 'company_id') {
                 $company = Contacts::findById($id);
                 if ($company instanceof Contact && $company->getIsCompany()) {
                     $value = $company->getObjectName();
                 }
             } else {
                 if ($field == 'rel_object_id') {
                     $value = $id;
                 } else {
                     if ($manager instanceof ContentDataObjects) {
                         $value = $manager->getExternalColumnValue($field, $id);
                     }
                 }
             }
         }
     }
     Hook::fire('custom_reports_get_external_column_value', array('field' => $field, 'external_id' => $id, 'manager' => $manager, 'object' => $object), $value);
     return $value;
 }
Пример #24
0
 function getDashboardObject()
 {
     //FIXME
     $wsIds = $this->getWorkspacesIdsCSV(logged_user()->getWorkspacesQuery());
     if ($this->getUpdatedById() > 0 && $this->getUpdatedBy() instanceof Contact) {
         $updated_by_id = $this->getUpdatedBy()->getObjectId();
         $updated_by_name = $this->getUpdatedByDisplayName();
         $updated_on = $this->getObjectUpdateTime() instanceof DateTimeValue ? $this->getObjectUpdateTime()->isToday() ? format_time($this->getObjectUpdateTime()) : format_datetime($this->getObjectUpdateTime()) : lang('n/a');
     } else {
         if ($this->getCreatedById() > 0 && $this->getCreatedBy() instanceof Contact) {
             $updated_by_id = $this->getCreatedBy()->getId();
         } else {
             $updated_by_id = lang('n/a');
         }
         $updated_by_name = $this->getCreatedByDisplayName();
         $updated_on = $this->getObjectCreationTime() instanceof DateTimeValue ? $this->getObjectCreationTime()->isToday() ? format_time($this->getObjectCreationTime()) : format_datetime($this->getObjectCreationTime()) : lang('n/a');
     }
     $deletedOn = $this->getTrashedOn() instanceof DateTimeValue ? $this->getTrashedOn()->isToday() ? format_time($this->getTrashedOn()) : format_datetime($this->getTrashedOn(), 'M j') : lang('n/a');
     if ($this->getTrashedById() > 0) {
         $deletedBy = Contacts::findById($this->getTrashedById());
     }
     if (isset($deletedBy) && $deletedBy instanceof Contact) {
         $deletedBy = $deletedBy->getObjectName();
     } else {
         $deletedBy = lang("n/a");
     }
     $archivedOn = $this->getArchivedOn() instanceof DateTimeValue ? $this->getArchivedOn()->isToday() ? format_time($this->getArchivedOn()) : format_datetime($this->getArchivedOn(), 'M j') : lang('n/a');
     if ($this->getArchivedById() > 0) {
         $archivedBy = Contacts::findById($this->getArchivedById());
     }
     if (isset($archivedBy) && $archivedBy instanceof Contact) {
         $archivedBy = $archivedBy->getObjectName();
     } else {
         $archivedBy = lang("n/a");
     }
     return array("id" => $this->getObjectTypeName() . $this->getId(), "object_id" => $this->getId(), "ot_id" => $this->getObjectTypeId(), "name" => $this->getObjectName(), "type" => $this->getObjectTypeName(), "tags" => project_object_tags($this), "createdBy" => $this->getCreatedByDisplayName(), "createdById" => $this->getCreatedById(), "dateCreated" => $this->getObjectCreationTime() instanceof DateTimeValue ? $this->getObjectCreationTime()->isToday() ? format_time($this->getObjectCreationTime()) : format_datetime($this->getObjectCreationTime()) : lang('n/a'), "updatedBy" => $updated_by_name, "updatedById" => $updated_by_id, "dateUpdated" => $updated_on, "wsIds" => $wsIds, "url" => $this->getObjectUrl(), "manager" => get_class($this->manager()), "deletedById" => $this->getTrashedById(), "deletedBy" => $deletedBy, "dateDeleted" => $deletedOn, "archivedById" => $this->getArchivedById(), "archivedBy" => $archivedBy, "dateArchived" => $archivedOn);
 }
Пример #25
0
 function unarchive()
 {
     if (!can_manage_dimension_members(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $member = Members::findById(get_id());
     if (!$member instanceof Member) {
         flash_error(lang('member dnx'));
         ajx_current("empty");
         return;
     }
     if (get_id('user')) {
         $user = Contacts::findById($get_id('user'));
     } else {
         $user = logged_user();
     }
     if (!$user instanceof Contact) {
         ajx_current("empty");
         return;
     }
     try {
         DB::beginWork();
         set_time_limit(0);
         $count = $member->unarchive($user);
         evt_add("reload dimension tree", $member->getDimensionId());
         ajx_current("back");
         flash_success(lang('success unarchive member', $member->getName(), $count));
         DB::commit();
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
         ajx_current("empty");
     }
 }
Пример #26
0
function get_member_custom_property_value_for_listing($cp, $member_id, $cp_vals = null)
{
    if (is_null($cp_vals)) {
        $cp_vals = MemberCustomPropertyValues::getMemberCustomPropertyValues($member_id, $cp->getId());
    }
    $val_to_show = "";
    foreach ($cp_vals as $cp_val) {
        if (in_array($cp->getType(), array('contact', 'user')) && $cp_val instanceof MemberCustomPropertyValue) {
            $cp_contact = Contacts::findById($cp_val->getValue());
            if ($cp_contact instanceof Contact) {
                $cp_val->setValue($cp_contact->getObjectName());
            } else {
                $cp_val->setValue("");
            }
        }
        if ($cp->getType() == 'date' && $cp_val instanceof MemberCustomPropertyValue) {
            $format = user_config_option('date_format');
            Hook::fire("custom_property_date_format", null, $format);
            $tmp_date = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $cp_val->getValue());
            if (str_starts_with($cp_val->getValue(), EMPTY_DATE)) {
                $formatted = "";
            } else {
                if (str_ends_with($cp_val->getValue(), "00:00:00")) {
                    $formatted = $tmp_date->format(user_config_option('date_format'));
                } else {
                    $formatted = $tmp_date->format($format);
                }
            }
            $cp_val->setValue($formatted);
        }
        if ($cp->getType() == 'address' && $cp_val instanceof MemberCustomPropertyValue) {
            $values = str_replace("\\|", "%%_PIPE_%%", $cp_val->getValue());
            $exploded = explode("|", $values);
            foreach ($exploded as &$v) {
                $v = str_replace("%%_PIPE_%%", "|", $v);
                $v = str_replace("'", "\\'", $v);
            }
            if (count($exploded) > 0) {
                $address_type = array_var($exploded, 0, '');
                $street = array_var($exploded, 1, '');
                $city = array_var($exploded, 2, '');
                $state = array_var($exploded, 3, '');
                $country = array_var($exploded, 4, '');
                $zip_code = array_var($exploded, 5, '');
                $country_name = CountryCodes::getCountryNameByCode($country);
                $tmp = array();
                if ($street != '') {
                    $tmp[] = $street;
                }
                if ($city != '') {
                    $tmp[] = $city;
                }
                if ($state != '') {
                    $tmp[] = $state;
                }
                if ($zip_code != '') {
                    $tmp[] = $zip_code;
                }
                if ($country_name != '') {
                    $tmp[] = $country_name;
                }
                $cp_val->setValue(implode(' - ', $tmp));
            }
        }
        $val_to_show .= ($val_to_show == "" ? "" : ", ") . ($cp_val instanceof MemberCustomPropertyValue ? $cp_val->getValue() : "");
    }
    $val_to_show = html_to_text($val_to_show);
    return $val_to_show;
}
Пример #27
0
?>
';
</script>

<?php 
define('PX_HEIGHT', 42);
$year = isset($_GET['year']) ? $_GET['year'] : (isset($_SESSION['year']) ? $_SESSION['year'] : date('Y'));
$month = isset($_GET['month']) ? $_GET['month'] : (isset($_SESSION['month']) ? $_SESSION['month'] : date('n'));
$day = isset($_GET['day']) ? $_GET['day'] : (isset($_SESSION['day']) ? $_SESSION['day'] : date('j'));
$_SESSION['year'] = $year;
$_SESSION['month'] = $month;
$_SESSION['day'] = $day;
$user_filter = $userPreferences['user_filter'];
$status_filter = $userPreferences['status_filter'];
$task_filter = $userPreferences['task_filter'];
$user = Contacts::findById(array('id' => $user_filter));
if ($user == null) {
    $user = logged_user();
}
$use_24_hours = user_config_option('time_format_use_24');
$date_format = user_config_option('date_format');
if ($use_24_hours) {
    $timeformat = 'G:i';
} else {
    $timeformat = 'g:i A';
}
echo stylesheet_tag('event/day.css');
//today in gmt 0
$today = DateTimeValueLib::now();
//user today
//	$today->add('h', logged_user()->getTimezone());
Пример #28
0
 function list_files()
 {
     ajx_current("empty");
     // get query parameters
     $start = (int) array_var($_GET, 'start');
     $limit = (int) array_var($_GET, 'limit');
     if (!$start) {
         $start = 0;
     }
     if (!$limit) {
         $limit = config_option('files_per_page');
     }
     $order = array_var($_GET, 'sort');
     $order_dir = array_var($_GET, 'dir');
     $page = (int) ($start / $limit) + 1;
     $hide_private = !logged_user()->isMemberOfOwnerCompany();
     $type = array_var($_GET, 'type');
     $user = array_var($_GET, 'user');
     // if there's an action to execute, do so
     if (array_var($_GET, 'action') == 'delete') {
         $ids = explode(',', array_var($_GET, 'objects'));
         $succ = 0;
         $err = 0;
         foreach ($ids as $id) {
             $file = ProjectFiles::findById($id);
             if (isset($file) && $file->canDelete(logged_user())) {
                 try {
                     DB::beginWork();
                     $file->trash();
                     DB::commit();
                     ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH);
                     $succ++;
                 } catch (Exception $e) {
                     DB::rollback();
                     $err++;
                 }
             } else {
                 if (!$file instanceof ProjectFile) {
                     evt_add("popup", array('title' => lang('error'), 'message' => lang("file dnx")));
                 } else {
                     if (!$file->canDelete(logged_user())) {
                         evt_add("popup", array('title' => lang('error'), 'message' => lang("cannot delete file", $file->getObjectName())));
                     }
                 }
                 $err++;
             }
         }
         if ($succ > 0) {
             flash_success(lang("success delete files", $succ));
         } else {
             flash_error(lang("error delete files", $err));
         }
     } else {
         if (array_var($_GET, 'action') == 'markasread') {
             $ids = explode(',', array_var($_GET, 'objects'));
             $succ = 0;
             $err = 0;
             foreach ($ids as $id) {
                 $file = ProjectFiles::findById($id);
                 try {
                     $file->setIsRead(logged_user()->getId(), true);
                     $succ++;
                 } catch (Exception $e) {
                     $err++;
                 }
                 // try
             }
             //for
             if ($succ <= 0) {
                 flash_error(lang("error markasread files", $err));
             }
         } else {
             if (array_var($_GET, 'action') == 'markasunread') {
                 $ids = explode(',', array_var($_GET, 'objects'));
                 $succ = 0;
                 $err = 0;
                 foreach ($ids as $id) {
                     $file = ProjectFiles::findById($id);
                     try {
                         $file->setIsRead(logged_user()->getId(), false);
                         $succ++;
                     } catch (Exception $e) {
                         $err++;
                     }
                     // try
                 }
                 //for
                 if ($succ <= 0) {
                     flash_error(lang("error markasunread files", $err));
                 }
             } else {
                 if (array_var($_GET, 'action') == 'zip_add') {
                     $this->zip_add();
                 } else {
                     if (array_var($_GET, 'action') == 'archive') {
                         $ids = explode(',', array_var($_GET, 'ids'));
                         $succ = 0;
                         $err = 0;
                         foreach ($ids as $id) {
                             $file = ProjectFiles::findById($id);
                             if (isset($file) && $file->canEdit(logged_user())) {
                                 try {
                                     DB::beginWork();
                                     $file->archive();
                                     DB::commit();
                                     ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE);
                                     $succ++;
                                 } catch (Exception $e) {
                                     DB::rollback();
                                     $err++;
                                 }
                             } else {
                                 $err++;
                             }
                         }
                         if ($succ > 0) {
                             flash_success(lang("success archive objects", $succ));
                         } else {
                             flash_error(lang("error archive objects", $err));
                         }
                     }
                 }
             }
         }
     }
     Hook::fire('classify_action', null, $ret);
     $join_params = null;
     $select_columns = null;
     $extra_conditions = "";
     if (strpos($order, 'p_') == 1) {
         $cpId = substr($order, 3);
         $order = 'customProp';
     }
     if ($order == ProjectFiles::ORDER_BY_POSTTIME) {
         $order = '`created_on`';
     } else {
         if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) {
             $order = '`updated_on`';
         } else {
             if ($order == ProjectFiles::ORDER_BY_SIZE) {
                 $order = '`jt`.`filesize`';
                 $join_params = array('table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'file_id', 'e_field' => 'object_id');
                 $extra_conditions .= " AND `jt`.`object_id` = (SELECT max(`x`.`object_id`) FROM " . TABLE_PREFIX . "project_file_revisions `x` WHERE `x`.`file_id` = `e`.`object_id`)";
             } else {
                 if ($order == 'customProp') {
                     $order = 'IF(ISNULL(jt.value),1,0),jt.value';
                     $join_params['join_type'] = "LEFT ";
                     $join_params['table'] = "" . TABLE_PREFIX . "custom_property_values";
                     $join_params['jt_field'] = "object_id";
                     $join_params['e_field'] = "object_id";
                     $join_params['on_extra'] = "AND custom_property_id = " . $cpId;
                     $extra_conditions .= " AND ( custom_property_id = " . $cpId . " OR custom_property_id IS NULL)";
                     $select_columns = array("DISTINCT o.*", "e.*");
                 } else {
                     $order = '`name`';
                 }
             }
         }
     }
     // if
     $extra_conditions .= $hide_private ? 'AND `is_visible` = 1' : '';
     // filter attachments of other people if not filtering
     $tmp_mids = array();
     foreach (active_context() as $selection) {
         if ($selection instanceof Member) {
             $d = $selection->getDimension();
             if ($d instanceof Dimension && $d->getIsManageable()) {
                 $tmp_mids[] = $selection->getId();
             }
         }
     }
     if (count($tmp_mids) == 0) {
         if (Plugins::instance()->isActivePlugin('mail')) {
             $extra_conditions .= " AND IF(e.mail_id=0, true, EXISTS (SELECT mac.contact_id FROM " . TABLE_PREFIX . "mail_account_contacts mac \r\n\t\t\t\t\tWHERE mac.contact_id=o.created_by_id AND mac.account_id=(SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=e.mail_id)))";
         }
     }
     Hook::fire("listing_extra_conditions", null, $extra_conditions);
     $only_count_result = array_var($_GET, 'only_result', false);
     $context = active_context();
     $objects = ProjectFiles::instance()->listing(array("order" => $order, "order_dir" => $order_dir, "extra_conditions" => $extra_conditions, "show_only_member_objects" => user_config_option('show_only_member_files'), 'count_results' => false, 'only_count_results' => $only_count_result, "join_params" => $join_params, "start" => $start, "limit" => $limit, "select_columns" => $select_columns));
     $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId());
     // prepare response object
     $listing = array("totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array());
     if (is_array($objects->objects)) {
         $index = 0;
         $ids = array();
         foreach ($objects->objects as $o) {
             $coName = "";
             $coId = $o->getCheckedOutById();
             if ($coId != 0) {
                 if ($coId == logged_user()->getId()) {
                     $coName = "self";
                 } else {
                     $coUser = Contacts::findById($coId);
                     if ($coUser instanceof Contact) {
                         $coName = $coUser->getObjectName();
                     } else {
                         $coName = "";
                     }
                 }
             }
             if ($o->isMP3()) {
                 $songname = $o->getProperty("songname");
                 $artist = $o->getProperty("songartist");
                 $album = $o->getProperty("songalbum");
                 $track = $o->getProperty("songtrack");
                 $year = $o->getProperty("songyear");
                 $duration = $o->getProperty("songduration");
                 $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId()));
             } else {
                 $songInfo = array();
             }
             $ids[] = $o->getId();
             $values = array("id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn()) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn()) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersIdsToDisplayPath()), "genid" => gen_id());
             if ($o->isMP3()) {
                 $values['isMP3'] = true;
             }
             Hook::fire('add_classification_value', $o, $values);
             foreach ($custom_properties as $cp) {
                 $values['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $o);
             }
             $listing["files"][] = $values;
         }
         $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId());
         foreach ($listing["files"] as &$data) {
             $data['isRead'] = isset($read_objects[$data['object_id']]);
         }
         ajx_extra_data($listing);
         tpl_assign("listing", $listing);
     } else {
         throw new Error("Not array", $code);
     }
 }
Пример #29
0
  function getDashboardObject(){
    	$projectId = "0";
    	$project = "";
    	if (count($this->getWorkspaces()) > 0) {
    		$type = "email";
    	} else {
    		$type = "emailunclassified";
    	}
    	$tags = project_object_tags($this);
    	
    	$deletedOn = $this->getTrashedOn() instanceof DateTimeValue ? ($this->getTrashedOn()->isToday() ? format_time($this->getTrashedOn()) : format_datetime($this->getTrashedOn(), 'M j')) : lang('n/a');
		if ($this->getTrashedById() > 0)
			$deletedBy = Contacts::findById($this->getTrashedById());
    	if (isset($deletedBy) && $deletedBy instanceof Contact) {
    		$deletedBy = $deletedBy->getObjectName();
    	} else {
    		$deletedBy = lang("n/a");
    	}
		
    	if ($this->getState() == 1 || $this->getState() == 3 || $this->getState() == 5) {
    		$createdBy = $this->getCreatedBy();
    	}
    	if (isset($createdBy) && $createdBy instanceof Contact) {
    		$createdById = $createdBy->getId();
    		$createdBy = $createdBy->getObjectName();
    	} else {
    		$createdById = 0;
    		$createdBy = $this->getFromName();
    	}
    	
  		$archivedOn = $this->getArchivedOn() instanceof DateTimeValue ? ($this->getArchivedOn()->isToday() ? format_time($this->getArchivedOn()) : format_datetime($this->getArchivedOn(), 'M j')) : lang('n/a');
  		if ($this->getArchivedById() > 0)
			$archivedBy = Contacts::findById($this->getArchivedById());
    	if (isset($archivedBy) &&  $archivedBy instanceof Contact) {
    		$archivedBy = $archivedBy->getObjectName();
    	} else {
    		$archivedBy = lang("n/a");
    	}
    	
    	$sentTimestamp = $this->getReceivedDate() instanceof DateTimeValue ? ($this->getReceivedDate()->isToday() ? format_time($this->getReceivedDate()) : format_datetime($this->getReceivedDate())) : lang('n/a');
    	
		return array(
				"id" => $this->getObjectTypeName() . $this->getId(),
				"object_id" => $this->getId(),
				"name" => $this->getObjectName() != "" ? $this->getObjectName():lang('no subject'),
				"type" => $type,
				"tags" => $tags,
				"createdBy" => $createdBy,
				"createdById" => $createdById,
				"dateCreated" => $sentTimestamp,
				"updatedBy" => $createdBy,
				"updatedById" => $createdById,
				"dateUpdated" => $sentTimestamp,
				"wsIds" => $this->getWorkspacesIdsCSV(logged_user()->getWorkspacesQuery()),
    			"url" => $this->getObjectUrl(),
				"manager" => get_class($this->manager()),
    			"deletedById" => $this->getTrashedById(),
    			"deletedBy" => $deletedBy,
    			"dateDeleted" => $deletedOn,
    			"archivedById" => $this->getArchivedById(),
    			"archivedBy" => $archivedBy,
    			"dateArchived" => $archivedOn,
				"subject" => $this->getSubject(),
				"isRead" => $this->getIsRead(logged_user()->getId())
		);
	}
Пример #30
0
 /**
  * Send password expiration reminders to contacts
  *
  * @access public
  * @return int
  */
 static function sendPasswordExpirationReminders()
 {
     $sent = 0;
     $password_expiration_days = config_option('password_expiration', 0);
     $password_expiration_notification = config_option('password_expiration_notification', 0);
     $contact_passwords = ContactPasswords::getNewestContactPasswords();
     foreach ($contact_passwords as $password) {
         $diff_days = self::getContactPasswordDays($password);
         if ($diff_days == $password_expiration_days - $password_expiration_notification) {
             $contact = Contacts::findById($password->getContactId());
             if ($contact instanceof Contact) {
                 if (Notifier::passwordExpiration($contact, $password_expiration_notification)) {
                     $sent++;
                 }
             }
         }
     }
     return $sent;
 }