Esempio n. 1
0
function workspaces_override_member_color($member, &$color) {
	
	$ws_ot = ObjectTypes::findByName('workspace');
	if (!$ws_ot instanceof ObjectType) return;
	
	if ($member->getObjectTypeId() == $ws_ot->getId()) {
		$ws = Workspaces::getWorkspaceById($member->getObjectId());
		if ($ws instanceof Workspace) {
			$color = $ws->getColumnValue('color');
		}
	}
}
Esempio n. 2
0
function workspaces_update_5_6()
{
    // create associations
    DB::execute("\n\t\t\tINSERT INTO `" . TABLE_PREFIX . "dimension_member_associations` (`dimension_id`,`object_type_id`,`associated_dimension_id`, `associated_object_type_id`, `is_required`,`is_multiple`, `keeps_record`) VALUES\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'person' LIMIT 1),0,1,0),\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'company' LIMIT 1),0,1,0);\n\t\t");
    // instantiate actual associations
    $ws_dim = Dimensions::findByCode('workspaces');
    $ws_ot = ObjectTypes::findByName('workspace');
    $ws_members = Members::findAll(array('conditions' => 'dimension_id = ' . $ws_dim->getId() . ' AND object_type_id = ' . $ws_ot->getId()));
    foreach ($ws_members as $ws_mem) {
        // after saving permissions the associations are instantiated by 'core_dimensions' plugin
        save_member_permissions($ws_mem);
    }
}
 function getObjectTypeId()
 {
     if (!$this instanceof ContentDataObjects || is_null($this->object_type_name)) {
         return null;
     }
     if (is_null($this->object_type_id)) {
         $ot = ObjectTypes::findByName($this->object_type_name);
         if ($ot instanceof ObjectType) {
             $this->object_type_id = $ot->getId();
         }
     }
     return $this->object_type_id;
 }
 /**
  * 
  * Checks if user can access the member for a specified access level
  * @param $permission_group_ids - string array: User permission group ids
  * @param $member_id - integer: Member Id
  * @param $user - Contact
  * @param $access_level - enum: ACCESS_LEVEL_READ, ACCESS_LEVEL_WRITE, ACCESS_LEVEL_DELETE
  * @param $check_administrator bool - if user is super administrator do not check permission
  */
 function contactCanAccessMemberAll($permission_group_ids, $member_id, $user, $access_level, $check_administrator = true)
 {
     if ($user instanceof Contact && $user->isAdministrator() && $check_administrator) {
         return true;
     }
     $member = Members::findById($member_id);
     if ($member instanceof Member && !$member->getDimension()->getDefinesPermissions()) {
         return true;
     }
     $disabled_ots = array();
     $disableds = DB::executeAll("SELECT object_type_id FROM " . TABLE_PREFIX . "tab_panels WHERE object_type_id>0 AND enabled=0");
     if (is_array($disableds)) {
         $disabled_ots = array_flat($disableds);
     }
     $ws_ot = ObjectTypes::findByName('workspace')->getId();
     $comment_ot = ObjectTypes::findByName('comment')->getId();
     $disabled_ots[] = $ws_ot;
     $disabled_ots[] = $comment_ot;
     $disabled_ot_cond = "";
     if (count($disabled_ots) > 0) {
         $disabled_ot_cond = "AND object_type_id NOT IN (" . implode(",", $disabled_ots) . ")";
     }
     if ($access_level == ACCESS_LEVEL_READ) {
         if (!isset(self::$readable_members["{$permission_group_ids}"])) {
             $res = DB::execute("SELECT DISTINCT member_id FROM " . TABLE_PREFIX . "contact_member_permissions WHERE permission_group_id IN (" . $permission_group_ids . ") {$disabled_ot_cond}");
             $rows = $res->fetchAll();
             if (is_array($rows)) {
                 self::$readable_members["{$permission_group_ids}"] = array();
                 foreach ($rows as $row) {
                     self::$readable_members["{$permission_group_ids}"][] = $row['member_id'];
                 }
             }
         }
         return in_array($member_id, self::$readable_members["{$permission_group_ids}"]);
     } else {
         if (!isset(self::$writable_members["{$permission_group_ids}"])) {
             $res = DB::execute("SELECT DISTINCT member_id FROM " . TABLE_PREFIX . "contact_member_permissions WHERE can_write=1 AND permission_group_id IN (" . $permission_group_ids . ") {$disabled_ot_cond}");
             $rows = $res->fetchAll();
             if (is_array($rows)) {
                 self::$writable_members["{$permission_group_ids}"] = array();
                 foreach ($rows as $row) {
                     self::$writable_members["{$permission_group_ids}"][] = $row['member_id'];
                 }
             }
         }
         return in_array($member_id, self::$writable_members["{$permission_group_ids}"]);
     }
 }
 /**
  * Render form control
  *
  * @param string $control_name
  * @return string
  */
 function render($control_name)
 {
     $options = array();
     $contact_types[] = array(ObjectTypes::findByName("contact")->getId(), lang("contact"));
     $contact_types[] = array(ObjectTypes::findByName("company")->getId(), lang("company"));
     $unknown_id = 0;
     $option_attributes = $this->getRawValue() == $unknown_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("unknown"), $unknown_id, $option_attributes);
     $contact_id = ObjectTypes::findByName("contact")->getId();
     $option_attributes = $this->getRawValue() == $contact_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("contact"), $contact_id, $option_attributes);
     $company_id = ObjectTypes::findByName("company")->getId();
     $option_attributes = $this->getRawValue() == $company_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("company"), $company_id, $option_attributes);
     return select_box($control_name, $options);
 }
 function list_all()
 {
     ajx_current("empty");
     // Get all variables from request
     $start = array_var($_GET, 'start', 0);
     $limit = array_var($_GET, 'limit', config_option('files_per_page'));
     $order = 'name';
     $order_dir = array_var($_GET, 'dir');
     $action = array_var($_GET, 'action');
     $attributes = array("ids" => explode(',', array_var($_GET, 'ids')));
     if (!$order_dir) {
         switch ($order) {
             case 'name':
                 $order_dir = 'ASC';
                 break;
             default:
                 $order_dir = 'DESC';
         }
     }
     $dim_controller = new DimensionController();
     $members = $dim_controller->initial_list_dimension_members(Dimensions::findByCode('workspaces')->getId(), ObjectTypes::findByName('workspace')->getId(), $context, true);
     $ids = array();
     foreach ($members as $m) {
         $ids[] = $m['object_id'];
     }
     $members = active_context_members(false);
     // Context Members Ids
     $members_sql = "";
     if (count($members) > 0) {
         $members_sql .= " AND parent_member_id IN (" . implode(',', $members) . ")";
     } else {
         $members_sql .= " AND parent_member_id = 0";
     }
     $res = Members::findAll(array("conditions" => "object_id IN (" . implode(',', $ids) . ") " . $members_sql, 'offset' => $start, 'limit' => $limit, 'order' => "{$order} {$order_dir}"));
     $object = $this->prepareObject($res, $start, $limit, count($res));
     ajx_extra_data($object);
     tpl_assign("listing", $object);
 }
 private function get_allowed_columns($object_type)
 {
     $fields = array();
     if (isset($object_type)) {
         $customProperties = CustomProperties::getAllCustomPropertiesByObjectType($object_type);
         $objectFields = array();
         foreach ($customProperties as $cp) {
             if ($cp->getType() == 'table') {
                 continue;
             }
             $fields[] = array('id' => $cp->getId(), 'name' => $cp->getName(), 'type' => $cp->getType(), 'values' => $cp->getValues(), 'multiple' => $cp->getIsMultipleValues());
         }
         $ot = ObjectTypes::findById($object_type);
         eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();");
         $objectColumns = $managerInstance->getColumns();
         $objectFields = array();
         $objectColumns = array_diff($objectColumns, $managerInstance->getSystemColumns());
         foreach ($objectColumns as $column) {
             $objectFields[$column] = $managerInstance->getColumnType($column);
         }
         $common_columns = Objects::instance()->getColumns(false);
         $common_columns = array_diff_key($common_columns, array_flip($managerInstance->getSystemColumns()));
         $objectFields = array_merge($objectFields, $common_columns);
         foreach ($objectFields as $name => $type) {
             if ($type == DATA_TYPE_FLOAT || $type == DATA_TYPE_INTEGER) {
                 $type = 'numeric';
             } else {
                 if ($type == DATA_TYPE_STRING) {
                     $type = 'text';
                 } else {
                     if ($type == DATA_TYPE_BOOLEAN) {
                         $type = 'boolean';
                     } else {
                         if ($type == DATA_TYPE_DATE || $type == DATA_TYPE_DATETIME) {
                             $type = 'date';
                         }
                     }
                 }
             }
             $field_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $name);
             if (is_null($field_name)) {
                 $field_name = lang('field Objects ' . $name);
             }
             $fields[] = array('id' => $name, 'name' => $field_name, 'type' => $type);
         }
         $externalFields = $managerInstance->getExternalColumns();
         foreach ($externalFields as $extField) {
             $field_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $extField);
             if (is_null($field_name)) {
                 $field_name = lang('field Objects ' . $extField);
             }
             $fields[] = array('id' => $extField, 'name' => $field_name, 'type' => 'external', 'multiple' => 0);
         }
         //if Object type is person
         $objType = ObjectTypes::findByName('contact');
         if ($objType instanceof ObjectType) {
             if ($object_type == $objType->getId()) {
                 $fields[] = array('id' => 'email_address', 'name' => lang('email address'), 'type' => 'text');
                 $fields[] = array('id' => 'phone_number', 'name' => lang('phone number'), 'type' => 'text');
                 $fields[] = array('id' => 'web_url', 'name' => lang('web pages'), 'type' => 'text');
                 $fields[] = array('id' => 'im_value', 'name' => lang('instant messengers'), 'type' => 'text');
                 $fields[] = array('id' => 'address', 'name' => lang('address'), 'type' => 'text');
             }
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }
Esempio n. 8
0
function core_dimensions_update_9_10()
{
    $template_ot = ObjectTypes::findByName('template');
    $users = Contacts::getAllUsers();
    foreach ($users as $user) {
        /* @var $user Contact */
        if (!$user->isAdminGroup()) {
            continue;
        }
        // don't allow to write emails for collaborators and guests
        $user_type_name = $user->getUserTypeName();
        if ($template_ot instanceof ObjectType) {
            DB::executeAll("UPDATE " . TABLE_PREFIX . "contact_member_permissions SET can_write=1, can_delete=1 WHERE object_type_id=" . $template_ot->getId() . " AND permission_group_id=" . $user->getPermissionGroupId());
        }
    }
    $pgs = PermissionGroups::findAll(array("conditions" => "`name` in ('Super Administrator','Administrator')"));
    foreach ($pgs as $pg) {
        DB::executeAll("UPDATE " . TABLE_PREFIX . "role_object_type_permissions SET can_write=1, can_delete=1 WHERE object_type_id=" . $template_ot->getId() . " AND role_id=" . $user->getPermissionGroupId());
    }
}
 static function objectNotification($object, $people, $sender, $notification, $description = null, $descArgs = null, $properties = array(), $links = array())
 {
     if (!is_array($people) || !count($people)) {
         return;
     }
     if ($sender instanceof Contact) {
         $sendername = $sender->getObjectName();
         $senderemail = $sender->getEmailAddress();
         $senderid = $sender->getId();
     } else {
         $sendername = owner_company()->getObjectName();
         $senderemail = owner_company()->getEmailAddress();
         if (!is_valid_email($senderemail)) {
             $senderemail = '*****@*****.**';
         }
         $senderid = 0;
     }
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     $name = $object instanceof Comment ? $object->getRelObject()->getObjectName() : $object->getObjectName();
     $assigned_to = "";
     $assigned_by = "";
     if ($object instanceof ProjectTask) {
         if ($object->getAssignedTo() instanceof Contact) {
             $assigned_to = $object->getAssignedToName();
             if ($object->getAssignedBy() instanceof Contact) {
                 $assigned_by = $object->getAssignedBy()->getObjectName();
             }
         }
     }
     $text = "";
     //text, descripction or revision comment
     if ($object->columnExists('text') && trim($object->getColumnValue('text'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('text')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
         }
     }
     if ($object->columnExists('description') && trim($object->getColumnValue('description'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('description')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
         }
     }
     $text_comment = "";
     if ($object instanceof ProjectFile && $object->getType() == ProjectFiles::TYPE_DOCUMENT) {
         $revision = $object->getLastRevision();
         if (trim($revision->getComment())) {
             $text_comment = escape_html_whitespace("\n" . $revision->getComment());
         }
     }
     //context
     $contexts = array();
     $members = $object instanceof Comment ? $object->getRelObject()->getMembers() : $object->getMembers();
     // Do not send context when edit a user
     if (!($object instanceof Contact && $notification == 'modified' && $object->getUserType() > 0)) {
         if (count($members) > 0) {
             foreach ($members as $member) {
                 $dim = $member->getDimension();
                 if ($dim->getIsManageable()) {
                     /* @var $member Member */
                     $parent_members = $member->getAllParentMembersInHierarchy();
                     $parents_str = '';
                     foreach ($parent_members as $pm) {
                         /* @var $pm Member */
                         if (!$pm instanceof Member) {
                             continue;
                         }
                         $parents_str .= '<span style="' . get_workspace_css_properties($pm->getMemberColor()) . '">' . $pm->getName() . '</span>';
                     }
                     if ($dim->getCode() == "customer_project" || $dim->getCode() == "customers") {
                         $obj_type = ObjectTypes::findById($member->getObjectTypeId());
                         if ($obj_type instanceof ObjectType) {
                             $contexts[$dim->getCode()][$obj_type->getName()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                         }
                     } else {
                         $contexts[$dim->getCode()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                     }
                 }
             }
         }
     }
     $attachments = array();
     try {
         if ($object instanceof ProjectFile && ($object->getAttachToNotification() || $object->getFileType() && $object->getFileType()->getIsImage() && config_option('show images in document notifications') && in_array($object->getTypeString(), ProjectFiles::$image_types))) {
             if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
                 $file_path = FileRepository::getBackend()->getFilePath($object->getLastRevision()->getRepositoryId());
             } else {
                 $file_path = ROOT . "/tmp/" . $object->getFilename();
                 $handle = fopen($file_path, 'wb');
                 fwrite($handle, $object->getLastRevision()->getFileContent(), $object->getLastRevision()->getFilesize());
                 fclose($handle);
             }
             $att_disposition = 'attachment';
             if (config_option('show images in document notifications') && in_array($object->getTypeString(), ProjectFiles::$image_types)) {
                 $att_disposition = 'inline';
             }
             $attachments[] = array('cid' => gen_id() . substr($senderemail, strpos($senderemail, '@')), 'path' => $file_path, 'type' => $object->getTypeString(), 'disposition' => $att_disposition, 'name' => $object->getFilename());
         }
     } catch (FileNotInRepositoryError $e) {
         // don't interrupt notifications.
     }
     if (trim($name) == "") {
         $name = lang($object->getObjectTypeName()) . " (" . lang('id') . ": " . $object->getId() . ")";
     }
     tpl_assign('object', $object);
     tpl_assign('title', $name);
     //title
     tpl_assign('by', $assigned_by);
     //by
     tpl_assign('asigned', $assigned_to);
     //assigned to
     tpl_assign('description', $text);
     //descripction
     tpl_assign('revision_comment', $text_comment);
     //revision_comment
     tpl_assign('contexts', $contexts);
     //contexts
     $emails = array();
     $grouped_people = self::buildPeopleGroups($people);
     foreach ($grouped_people as $pgroup) {
         $lang = array_var($pgroup, 'lang');
         $timezone = array_var($pgroup, 'tz');
         $group_users = array_var($pgroup, 'groups');
         // contains arrays of users, with max size = 20 each one, a single email is sent foreach user group
         foreach ($group_users as $users) {
             $to_addresses = array();
             foreach ($users as $user) {
                 if (logged_user() instanceof Contact && logged_user()->getId() == $user->getId()) {
                     $user->notify_myself = logged_user()->notify_myself;
                 }
                 if (($user->getId() != $senderid || $user->notify_myself) && ($object->canView($user) || $user->ignore_permissions_for_notifications)) {
                     $to_addresses[$user->getId()] = self::prepareEmailAddress($user->getEmailAddress(), $user->getObjectName());
                 }
             }
             // build notification
             if (count($to_addresses) > 0) {
                 if ($object instanceof Comment) {
                     $subscribers = $object->getRelObject()->getSubscribers();
                 } else {
                     $subscribers = $object->getSubscribers();
                 }
                 //ALL SUBSCRIBERS
                 if (count($subscribers) > 0) {
                     $string_subscriber = '';
                     $total_s = count($subscribers);
                     $c = 0;
                     foreach ($subscribers as $subscriber) {
                         $c++;
                         if ($c == $total_s && $total_s > 1) {
                             $string_subscriber .= " " . lang('and') . " ";
                         } else {
                             if ($c > 1) {
                                 $string_subscriber .= ", ";
                             }
                         }
                         $string_subscriber .= $subscriber->getFirstName();
                         if ($subscriber->getSurname() != "") {
                             $string_subscriber .= " " . $subscriber->getSurname();
                         }
                     }
                     tpl_assign('subscribers', $string_subscriber);
                     // subscribers
                 }
                 // send notification on user's locale and with user info
                 Localization::instance()->loadSettings($lang, ROOT . '/language');
                 if ($object instanceof Comment) {
                     $object_comment = Objects::findObject($object->getRelObjectId());
                     $object_type_name = $object_comment->getObjectTypeName();
                 } else {
                     $object_type_name = '';
                 }
                 $object_type = strtolower(lang($object_type_name));
                 if ($object_type_name != "") {
                     tpl_assign('object_comment_name', lang("the " . strtolower($object_type_name) . " notification"));
                     //object_comment_name
                 }
                 if (!isset($description)) {
                     $descArgs = array(clean($name), $sendername, $object_type, $object->getCreatedByDisplayName());
                     $description = "{$notification} notification {$type} desc";
                 } else {
                     //reminders
                     $date = "";
                     //due
                     if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                         if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                     }
                     //start
                     if ($object->columnExists('start') && $object->getColumnValue('start')) {
                         if ($object->getColumnValue('start') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('start'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                     }
                     $descArgs = array(clean($name), $date != "" ? $date : $sendername, $object_type, $object->getCreatedByDisplayName(), $date);
                 }
                 tpl_assign('description_title', langA($description, $descArgs));
                 //description_title
                 tpl_assign('priority', '');
                 //priority
                 if ($object->columnExists('priority') && trim($object->getColumnValue('priority'))) {
                     if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_URGENT) {
                         $priorityColor = "#FF0000";
                         $priority = lang('urgent priority');
                     } else {
                         if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_HIGH) {
                             $priorityColor = "#FF9088";
                             $priority = lang('high priority');
                         } else {
                             if ($object->getColumnValue('priority') <= ProjectTasks::PRIORITY_LOW) {
                                 $priorityColor = "white";
                                 $priority = lang('low priority');
                             } else {
                                 $priorityColor = "#DAE3F0";
                                 $priority = lang('normal priority');
                             }
                         }
                     }
                     tpl_assign('priority', array($priority, $priorityColor));
                     //priority
                 }
                 //ESPECIAL ASSIGNED FOR EVENTS
                 tpl_assign('start', '');
                 //start
                 tpl_assign('time', '');
                 //time
                 tpl_assign('duration', '');
                 //duration
                 tpl_assign('guests', '');
                 // invitations
                 tpl_assign('start_date', '');
                 //start_date
                 tpl_assign('due_date', '');
                 //due_date
                 $event_ot = ObjectTypes::findByName('event');
                 if ($object->getObjectTypeId() == $event_ot->getId()) {
                     //start
                     if ($object->getStart() instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getStart(), $timezone);
                         $time = Localization::instance()->formatTime($object->getStart(), $timezone);
                         tpl_assign('start', $date);
                         //start
                         if ($object->getTypeId() != 2) {
                             tpl_assign('time', $time);
                             //time
                         }
                     }
                     if ($object->getTypeId() != 2) {
                         //duration
                         if ($object->getDuration() instanceof DateTimeValue) {
                             $durtime = $object->getDuration()->getTimestamp() - $object->getStart()->getTimestamp();
                             $durhr = $durtime / 3600 % 24;
                             //seconds per hour
                             tpl_assign('duration', $durhr . " hs");
                             //duration
                         }
                     } else {
                         tpl_assign('duration', lang('all day event'));
                         //duration
                     }
                     //invitations
                     $guests = "";
                     $send_link = array();
                     $invitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $object->getId()));
                     if (isset($invitations) && is_array($invitations)) {
                         foreach ($invitations as $inv) {
                             $inv_user = Contacts::findById($inv->getContactId());
                             if ($inv_user instanceof Contact) {
                                 if (can_access($inv_user, $object->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                                     $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');
                                             }
                                         }
                                     }
                                     $guests .= '<div style="line-height: 20px; clear:both;">';
                                     $guests .= '<div style="width: 35%;line-height: 20px; float: left;">' . clean($inv_user->getObjectName()) . '</div>';
                                     $guests .= '<div style="line-height: 20px; float: left;">' . $state_desc . '</div></div>';
                                 }
                                 if ($inv->getInvitationState() == 0) {
                                     $send_link[] = $inv_user->getId();
                                 }
                             }
                         }
                     }
                     tpl_assign('guests', $guests);
                     // invitations
                 } else {
                     //start date, due date or start
                     if ($object->columnExists('start_date') && $object->getColumnValue('start_date')) {
                         if ($object->getColumnValue('start_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('start_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                         tpl_assign('start_date', $date);
                         //start_date
                     }
                     if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                         if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                         tpl_assign('due_date', $date);
                         //due_date
                     }
                 }
                 $toemail = $user->getEmailAddress();
                 try {
                     $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
                     if ($content != "") {
                         $file_path = ROOT . "/tmp/logo_empresa.png";
                         $handle = fopen($file_path, 'wb');
                         if ($handle) {
                             fwrite($handle, $content);
                             fclose($handle);
                             $attachments['logo'] = array('cid' => gen_id() . substr($toemail, strpos($toemail, '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
                         }
                     }
                 } catch (FileNotInRepositoryError $e) {
                     unset($attachments['logo']);
                 }
                 tpl_assign('attachments', $attachments);
                 // attachments
                 $from = self::prepareEmailAddress($senderemail, $sendername);
                 if (!$toemail) {
                     continue;
                 }
                 $subject = htmlspecialchars_decode(langA("{$notification} notification {$type}", $descArgs));
                 if ($object instanceof ProjectFile && $object->getDefaultSubject() != "") {
                     $subject = $object->getDefaultSubject();
                     tpl_assign('description_title', $subject);
                 }
                 $recipients_field = config_option('notification_recipients_field', 'to');
                 $emails[] = array("{$recipients_field}" => $to_addresses, "from" => self::prepareEmailAddress($senderemail, $sendername), "subject" => $subject, "body" => tpl_fetch(get_template_path('general', 'notifier')), "attachments" => $attachments);
             }
         }
     }
     self::queueEmails($emails);
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
 }
 function get_template_tasks_data()
 {
     ajx_current("empty");
     $ids = explode(',', array_var($_REQUEST, 'ids'));
     foreach ($ids as $k => &$id) {
         if (!is_numeric($id)) {
             unset($ids[$k]);
         }
     }
     $objects = array();
     if (count($ids) > 0) {
         $tasks = TemplateTasks::findAll(array('conditions' => 'id IN (' . implode(',', $ids) . ')'));
         $ot = ObjectTypes::findByName('template_task');
         foreach ($tasks as $task) {
             $objects[] = $this->prepareObject($task->getId(), $task->getId(), $task->getObjectName(), $ot->getName(), $task->manager(), "", $task->getMilestoneId(), array(), $task->getParentId(), 'ico-task');
         }
     }
     ajx_extra_data(array('tasks' => $objects));
 }
Esempio n. 11
0
				//check email
				if(!og.checkValidEmailAddress(mail)){
					container.closest(".widget-body").removeClass("loading");
					og.err("<?php 
echo lang('invalid email address');
?>
");
					return;
				}
				
				var user_type = container.find('select[name="contact[user][type]"] option:selected').val();
				var company_id = container.find('select[name="contact[user][company_id]"] option:selected').val();
				
				var postVars = {
					'member[object_type_id]': <?php 
echo ObjectTypes::findByName('person')->getId();
?>
,
					'member[name]': value,
					'member[parent_member_id]' : parent,
					'member[dimension_id]': <?php 
echo Dimensions::findByCode('feng_persons')->getId();
?>
,
					'contact[email]': mail,
					'contact[user][create-user]' : create_user,
					'contact[user][type]': user_type,
					'contact[user][company_id]': company_id
				};

				var firstName = '';
function workspaces_additional_dashboard_actions($ignored, &$actions)
{
    $ws_dim = Dimensions::findByCode('workspaces');
    $wot = ObjectTypes::findByName('workspace');
    $wdot = DimensionObjectTypes::findOne(array('conditions' => 'dimension_id=' . $ws_dim->getId() . ' AND object_type_id=' . $wot->getId()));
    if ($wdot instanceof DimensionObjectType && $wdot->getEnabled()) {
        if (active_context_can_contain_member_type($ws_dim->getId(), $wot->getId())) {
            $actions[] = array('id' => 'workspaces-list', 'assoc_ot' => $wot->getId(), 'assoc_dim' => $ws_dim->getId(), 'name' => lang('workspaces list'), 'class' => 'link-ico ico-workspace', 'onclick' => "og.openLink(og.getUrl('member', 'init', {dim_id:" . $ws_dim->getId() . ", type_id:" . $wot->getId() . "}), {caller:'" . $ws_dim->getCode() . "'}); return false;");
        }
    }
    $tags_dim = Dimensions::findByCode('tags');
    $tot = ObjectTypes::findByName('tag');
    $tdot = DimensionObjectTypes::findOne(array('conditions' => 'dimension_id=' . $tags_dim->getId() . ' AND object_type_id=' . $tot->getId()));
    if ($tdot instanceof DimensionObjectType && $tdot->getEnabled()) {
        if (active_context_can_contain_member_type($tags_dim->getId(), $tot->getId())) {
            $actions[] = array('id' => 'tags-list', 'assoc_ot' => $tot->getId(), 'assoc_dim' => $tags_dim->getId(), 'name' => lang('tags list'), 'class' => 'link-ico ico-tag', 'onclick' => "og.openLink(og.getUrl('member', 'init', {dim_id:" . $tags_dim->getId() . ", type_id:" . $tot->getId() . "}), {caller:'" . $tags_dim->getCode() . "'}); return false;");
        }
    }
}
	/**
	 * Execute search
	 * TODO: Performance gus: 
	 * Fetch only ids and execute a select statement by pk (fer each result)
	 * @param void
	 * @return null
	 */
	function search() {
		// Init vars
		$search_for = array_var($_GET, 'search_for');
        $search_dimension = array_var($_GET, 'search_dimension');
        $advanced = array_var($_GET, 'advanced');
		$minWordLength = $this->minWordLength($search_for);
		$useLike = ( $minWordLength && ($this->ignoreMinWordLength) && ($minWordLength < self::$MYSQL_MIN_WORD_LENGHT) );
		$search_pieces= explode(" ", $search_for);
		$search_string = "";
		if (!$useLike){
			// Prepare MATCH AGAINST string
			foreach ($search_pieces as $word ) {
				if (( strpos($word, "@") || strpos($word, ".") || strpos($word, ",")) === false ) {
					// STRING Dont containt special characheters that mysql use as separator. Noramal  flow 
					if ($this->wildCardSearch) {
						$word.="*";
					}
				}else{
					$word =  str_replace($this->mysqlWordSeparator, " +", $word) ;
				}
				if ( !str_starts_with($word, " ") ) {
					$word = " +".$word;
				}
				$search_string .= mysql_real_escape_string( $word ). " ";
			}
			$search_string = substr($search_string, 0 , -1);
		}else{
			// USE Like Query
			$search_string = mysql_real_escape_string($search_for, DB::connection()->getLink());
		}
		
		$this->search_for = $search_for;
		$limit = $this->limit;
		$start = array_var($_REQUEST, 'start' , $this->start);
		$this->start = $start;
		$limitTest = max( $this->limitTest , $this->limit);
		$filteredResults = 0;
		$uid = logged_user()->getId();
		
		if(!isset($search_dimension)){
			$members = active_context_members(false);
		}else{
			if($search_dimension == 0){
				$members = array();
			}else{
				$members = array($search_dimension);
			}
		}
		
		// click on search everywhere
		if (array_var($_REQUEST, 'search_all_projects')) {
			$members = array();
		}
		
		$revisionObjectTypeId = ObjectTypes::findByName("file revision")->getId();
		
		$members_sql = "";
		if(count($members) > 0){
			$members_sql = "AND (rel_object_id IN (SELECT object_id FROM " . TABLE_PREFIX . "object_members om 
					WHERE member_id IN (" . implode ( ',', $members ) . ") GROUP BY object_id HAVING count(member_id) = ".count($members).")
				OR o.object_type_id = $revisionObjectTypeId AND rel_object_id IN (SELECT fr.object_id FROM " . TABLE_PREFIX . "object_members om 
					INNER JOIN ".TABLE_PREFIX."project_file_revisions fr ON om.object_id=fr.file_id 
					WHERE member_id IN (" . implode ( ',', $members ) . ") GROUP BY object_id HAVING count(member_id) = ".count($members)."))";
			$this->search_dimension = implode ( ',', $members );
		}else{
			$this->search_dimension = 0;
		}

		$listableObjectTypeIds = implode(",",ObjectTypes::getListableObjectTypeIds());
		
		if($_POST) {
			
			$conditions = array_var($_POST, 'conditions');
			$search = array_var($_POST, 'search');
			$type_object = array_var($search, 'search_object_type_id');
			if(!is_array($conditions)) $conditions = array();
			$where_condiition = '';
			$conditions_view = array();
			$cont = 0;
			$joincp ="";
			foreach($conditions as $condition){
				$condValue = array_key_exists('value', $condition) ? $condition['value'] : '';
				if($condition['field_type'] == 'boolean'){
					$value = array_key_exists('value', $condition);
				}else if($condition['field_type'] == 'date'){
					if ($condValue != '') {
						$dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condValue);
						$value = date("m/d/Y", $dtFromWidget->getTimestamp());
					}
				}else{
					$value = mysql_real_escape_string($condValue, DB::connection()->getLink());
				}				
				$condition_condition = mysql_real_escape_string(array_var($condition, 'condition'), DB::connection()->getLink());
				$condition_field_name = mysql_real_escape_string(array_var($condition, 'field_name'), DB::connection()->getLink());
				$conditionLocal = "like";
				tpl_assign('type_object', $type_object);
				if (isset($condition['custom_property_id']) and is_numeric($condition['custom_property_id'])){
					$condition_field_name = 'value';
					$joincp = 'JOIN  fo_custom_property_values cp ON cp.object_id = so.rel_object_id';
				};
				
				if ($condition_condition == "=" or $condition_condition == ">" or $condition_condition == "<" or $condition_condition == "<>" or $condition_condition == ">=" or $condition_condition == "<="){
					$conditionLocal = $condition_condition;
				};	
				if($condition_field_name == "id"){
					$condition_field_name = "o`.`id" ;
				};			
				if($condition_condition == "like"){
					$where_condiition .= " AND `" . $condition_field_name . "` " . "like" . " '%" . $value . "%' ";
				}else if($condition_condition == "ends with"){
					$where_condiition .= " AND `" . $condition_field_name . "` " . "like" . " '%" . $value . "' ";
				}else if($condition_condition == "start with"){
					$where_condiition .= " AND `" . $condition_field_name . "` " . "like" . " '" . $value . "%' ";
				}else if($condition_condition == "not like"){
					$where_condiition .= " AND `" . $condition_field_name . "` " . "not like" . " '%" . $value . "%' ";
				}else{					
					$where_condiition .= " AND `" . $condition_field_name . "` " . $conditionLocal . " '" . $value . "' ";
				}
								
				$conditions_view[$cont]['id'] = $condition['id'];
				$conditions_view[$cont]['custom_property_id'] = $custom_prop_id;
				$conditions_view[$cont]['field_name'] = $condition['field_name'];
				$conditions_view[$cont]['condition'] = $condition['condition'];
				$conditions_view[$cont]['value'] = $value;
				$cont++;
			}
			tpl_assign('conditions', $conditions_view);

			if($type_object){
				$object_table = ObjectTypes::findById($type_object);
				$table = $object_table->getTableName();				
			}

			$sql = "
			SELECT  distinct(so.rel_object_id) AS id
			FROM ".TABLE_PREFIX."searchable_objects so
			".$joincp."
			INNER JOIN  ".TABLE_PREFIX.$table." nto ON nto.object_id = so.rel_object_id 
			INNER JOIN  ".TABLE_PREFIX."objects o ON o.id = so.rel_object_id 
			WHERE (
				(
					so.rel_object_id IN (
			    		SELECT object_id FROM ".TABLE_PREFIX."sharing_table WHERE group_id  IN (
			      			SELECT permission_group_id FROM ".TABLE_PREFIX."contact_permission_groups WHERE contact_id = $uid
			    		)
			 		)
			 	)
			) " . $where_condiition . $members_sql . " ORDER by o.updated_on DESC
			LIMIT $start, $limitTest ";			
		} else {
			
			$type_object = '';
			
			$sql = "	
			SELECT  distinct(so.rel_object_id) AS id
			FROM ".TABLE_PREFIX."searchable_objects so
			INNER JOIN  ".TABLE_PREFIX."objects o ON o.id = so.rel_object_id 
			WHERE (
				(	
					o.object_type_id = $revisionObjectTypeId AND  
					EXISTS ( 
						SELECT id FROM ".TABLE_PREFIX."sharing_table WHERE object_id  = ( SELECT file_id FROM ".TABLE_PREFIX."project_file_revisions WHERE object_id = o.id ) 
						AND group_id IN (SELECT permission_group_id FROM ".TABLE_PREFIX."contact_permission_groups WHERE contact_id = $uid )
					)
					
				) 
				OR (
					so.rel_object_id IN (
			    		SELECT object_id FROM ".TABLE_PREFIX."sharing_table WHERE group_id  IN (
			      			SELECT permission_group_id FROM ".TABLE_PREFIX."contact_permission_groups WHERE contact_id = $uid
			    		)
			 		)
			 	)
			)" . (($useLike) ? "AND	so.content LIKE '%$search_string%' " : "AND MATCH (so.content) AGAINST ('$search_string' IN BOOLEAN MODE) ") . " 
			AND o.object_type_id IN ($listableObjectTypeIds) " . $members_sql . "
			ORDER by o.updated_on DESC
			LIMIT $start, $limitTest ";
		}
		tpl_assign('type_object', $type_object);
		$db_search_results = array();
		$search_results_ids = array();
		$timeBegin = time();
		$res = DB::execute($sql);
		$timeEnd = time();
		
		while ($row = $res->fetchRow() ) {
			$search_results_ids[] = $row['id'] ;
		}
		// Prepare results for view to avoid processing at presentation layer 
		$search_results = $this->prepareResults($search_results_ids, $null, $limit);
		
		// Calculate or approximate total for pagination
		$total = count($search_results_ids) + $start ;
		
		if ( count ( $search_results_ids ) < $limitTest ) {
			$total = count($search_results_ids) + $start ;
		}else{
			$total = "Many" ;
		}
		//$total -= $filteredResults ;
		$this->total = $total ;
		
		// Pagination
		$this->buildPagination($search_results, $search_for);
		
		// Extra data
		$extra = new stdClass() ;
		if ($this->showQueryTime) {
			$extra->time = $timeEnd-$timeBegin ;
		}
		//$extra->filteredResults = $filteredResults ;

		// Template asigns
		tpl_assign('pagination', $this->pagination);
		tpl_assign('search_string', $search_for);
		tpl_assign('search_dimension', $this->search_dimension);
		tpl_assign('search_results', $search_results);
		tpl_assign('advanced', $advanced);
		tpl_assign('extra', $extra );

		$types = array(array("", lang("select one")));
		$object_types = ObjectTypes::getAvailableObjectTypes();

		foreach ($object_types as $ot) {
			$types[] = array($ot->getId(), lang($ot->getName()));
		}
//		if ($selected_type != '')
//		tpl_assign('allowed_columns', $this->get_allowed_columns($selected_type));
		
		tpl_assign('object_types', $types);

		//Ajax
		if (!$total && !$advanced){
			if($_POST && count($search_results < 0)){
				tpl_assign('msg_advanced', true);
			}else{
				$this->setTemplate('no_results');
			}
		}
		ajx_set_no_toolbar(true);
		
	}
Esempio n. 14
0
function render_widget_option_input($widget_option, $genid = null)
{
    if (is_null($genid)) {
        $genid = gen_id();
    }
    $output = "";
    $name = 'widgets[' . $widget_option['widget'] . '][options][' . $widget_option['option'] . ']';
    switch ($widget_option['handler']) {
        case 'UserCompanyConfigHandler':
            if ($widget_option['widget'] == 'overdue_upcoming') {
                $ot = ObjectTypes::findByName('task');
            } else {
                break;
            }
            $users = allowed_users_in_context($ot->getId(), array(), ACCESS_LEVEL_READ, '', true);
            $output .= "<select name='{$name}' id='" . $genid . $name . "' onchange='og.on_widget_select_option_change(this);'>";
            $sel = $widget_option['value'] == 0 ? 'selected="selected"' : '';
            $output .= "<option value='0' {$sel}>" . lang('everyone') . "</option>";
            foreach ($users as $user) {
                $sel = $widget_option['value'] == $user->getId() ? 'selected="selected"' : '';
                $output .= "<option value='" . $user->getId() . "' {$sel}>" . $user->getObjectName() . "</option>";
            }
            $output .= "</select>";
            break;
        case 'BooleanConfigHandler':
            $output .= yes_no_widget($name, $genid . $name, $widget_option['value'], lang('yes'), lang('no'), null, array('onchange' => 'og.on_widget_radio_option_change(this);'));
            break;
        default:
            break;
    }
    return $output;
}
Esempio n. 15
0
<?php

$genid = gen_id();
$selectedPage = user_config_option('custom_report_tab');
$customReports = Reports::getAllReportsByObjectType();
$active_members = active_context_members(false);
if (count($active_members) > 0) {
    $report = new Report();
    $can_add_reports = $report->canAdd(logged_user(), active_context());
} else {
    $can_add_reports = logged_user()->isManager() || logged_user()->isAdminGroup();
}
$reports_by_type = array();
$object_types = ObjectTypes::getAvailableObjectTypes();
$object_types[] = ObjectTypes::findByName('timeslot');
Hook::fire('custom_reports_object_types', array('object_types' => $object_types), $object_types);
foreach ($object_types as $ot) {
    $reports_by_type[$ot->getId()] = array("name" => $ot->getName(), "display_name" => lang($ot->getName()), "icon_class" => $ot->getIconClass());
}
$ignored = null;
Hook::fire('modify_report_pages', $ignored, $reports_by_type);
// To add, edit or remove report pages
$default_reports = array('task time report' => array('url' => get_url('reporting', 'total_task_times_p'), 'name' => lang('task time report'), 'description' => lang('task time report description')));
Hook::fire('modify_default_reports', $ignored, $default_reports);
// To add, edit or remove default reports
Hook::fire('add_report_categories', $ignored, $report_categories);
Hook::fire('add_reports_by_category', $ignored, $reports_by_category);
require_javascript("og/ReportingFunctions.js");
?>

<div>
<div class="custom-properties"><?php 
require_javascript("og/CustomProperties.js");
$ot = ObjectTypes::findById($member->getObjectTypeId());
if ($ot->getName() == 'project_folder' || $ot->getName() == 'customer_folder') {
    $ot = ObjectTypes::findByName('folder');
}
$cps = MemberCustomProperties::getAllMemberCustomPropertiesByObjectType($ot->getId(), $visibility);
if ($visibility == 'others' && count($cps) == 0 && Plugins::instance()->isActivePlugin('member_custom_properties')) {
    echo lang('there are no custom properties defined message', strtolower(lang($ot->getName())), escape_character($member->getName()));
    echo '<br />' . lang('there are no custom properties defined link');
}
if (!$parent_member) {
    $parent_member = 0;
}
$ti = 0;
if (!isset($genid)) {
    $genid = gen_id();
}
if (!isset($startTi)) {
    $startTi = 10000;
}
if (count($cps) > 0) {
    $print_table_functions = false;
    foreach ($cps as $customProp) {
        if (!isset($required) || $required && ($customProp->getIsRequired() || $customProp->getVisibleByDefault()) || !$required && !($customProp->getIsRequired() || $customProp->getVisibleByDefault())) {
            $ti++;
            $cpv = MemberCustomPropertyValues::getMemberCustomPropertyValue($member->getId(), $customProp->getId());
            $default_value = $customProp->getDefaultValue();
            if ($cpv instanceof MemberCustomPropertyValue) {
                $default_value = $cpv->getValue();
            }
 function adjust_root_permissions($group, $root_perm_info = null)
 {
     // ROOT PERMISSIONS
     if (!is_null($root_perm_info)) {
         // user does not have permissions for object_type_ids
         $root_permissions_sharing_table_delete = array_var($root_perm_info, 'root_permissions_sharing_table_delete');
         if (is_array($root_permissions_sharing_table_delete)) {
             foreach ($root_permissions_sharing_table_delete as $object_type_id) {
                 $cond = "group_id={$group} AND object_id IN (SELECT o.id FROM " . TABLE_PREFIX . "objects o WHERE o.object_type_id = {$object_type_id} AND NOT EXISTS(\r\n\t\t\t\t\t\tSELECT om.object_id FROM " . TABLE_PREFIX . "object_members om WHERE om.object_id=o.id AND om.member_id IN (SELECT m.id FROM " . TABLE_PREFIX . "members m WHERE m.dimension_id IN (\r\n\t\t\t\t\t\t\tSELECT d.id FROM " . TABLE_PREFIX . "dimensions d WHERE d.is_manageable=1\r\n\t\t\t\t\t\t))\r\n\t\t\t\t\t))";
                 SharingTables::instance()->delete($cond);
             }
         }
         // user has permissions for object_type_ids
         $root_permissions_sharing_table_add = array_var($root_perm_info, 'root_permissions_sharing_table_add');
         if (is_array($root_permissions_sharing_table_add)) {
             $file_ot = ObjectTypes::findByName('file');
             foreach ($root_permissions_sharing_table_add as $object_type_id) {
                 $additional_where = "";
                 $additional_join = "";
                 if ($file_ot->getId() == $object_type_id && Plugins::instance()->isActivePlugin('mail')) {
                     $additional_join .= "INNER JOIN " . TABLE_PREFIX . "project_files e ON e.object_id=o.id";
                     $additional_where .= "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\t\t\tWHERE mac.contact_id IN (SELECT cpg.contact_id FROM " . TABLE_PREFIX . "contact_permission_groups cpg WHERE permission_group_id={$group}) \r\n\t\t\t\t\t\t\t\tAND mac.account_id=(SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=e.mail_id)))";
                 }
                 $sql = "SELECT o.id FROM " . TABLE_PREFIX . "objects o {$additional_join} WHERE o.object_type_id = {$object_type_id} AND NOT EXISTS(\r\n\t\t\t\t\t\tSELECT om.object_id FROM " . TABLE_PREFIX . "object_members om WHERE om.object_id=o.id AND om.member_id IN (SELECT m.id FROM " . TABLE_PREFIX . "members m WHERE m.dimension_id IN (\r\n\t\t\t\t\t\t\tSELECT d.id FROM " . TABLE_PREFIX . "dimensions d WHERE d.is_manageable=1\r\n\t\t\t\t\t\t))\r\n\t\t\t\t\t) {$additional_where}";
                 $rows = DB::executeAll($sql);
                 $ids = array_flat($rows);
                 $values = "";
                 foreach ($ids as $id) {
                     $values .= ($values == "" ? "" : ",") . "('{$id}','{$group}')";
                 }
                 DB::execute("INSERT INTO " . TABLE_PREFIX . "sharing_table (object_id, group_id) VALUES {$values} ON DUPLICATE KEY UPDATE group_id=group_id;");
             }
         }
     }
 }
Esempio n. 18
0
			container.closest(".widget-body").addClass("loading");
			
			var value = $(container).find("input.add-person-field").val();
			if (value) {
				
				var parent = 0 ;
				var create_user = ( container.find('input[name="contact[user][create-user]"]').is(':checked') ) ?'on':'' ;
				//var password = container.find('input[name="contact[user][password]"]').val();
				//var password_a =container.find('input[name="contact[user][password_a]"]').val();
				var mail = container.find('input[name="contact[email]"]').val();
				
				var user_type = container.find('select[name="contact[user][type]"] option:selected').val();
				var company_id = container.find('select[name="contact[user][company_id]"] option:selected').val();
				
				var postVars = {
					'member[object_type_id]': <?php echo ObjectTypes::findByName('person')->getId()?> ,
					'member[name]': value,
					'member[parent_member_id]' : parent,
					'member[dimension_id]': <?php echo Dimensions::findByCode('feng_persons')->getId()?>,
					'contact[email]': mail,
					'contact[user][create-user]' : create_user,
					'contact[user][type]': user_type,
					'contact[user][company_id]': company_id
				};

				var firstName = '';
				var surname = '';
				var nameParts = value.split(' ');
				if (nameParts && nameParts.length > 1) {
					for ( var i in nameParts ){
						if (i == "remove") continue;
Esempio n. 19
0
function permission_member_form_parameters($member = null, $dimension_id = null)
{
    if ($member) {
        $dim = $member->getDimension();
    } elseif (array_var($_REQUEST, 'dim_id')) {
        $dim = Dimensions::getDimensionById(array_var($_REQUEST, 'dim_id'));
    } elseif (!is_null($dimension_id)) {
        $dim = Dimensions::getDimensionById($dimension_id);
    }
    if (!$dim instanceof Dimension) {
        Logger::log("Invalid dimension: " . ($member instanceof Member ? " for member " . $member->getId() : "request: " . print_r($_REQUEST, 1)));
        throw new Exception("Invalid dimension");
    }
    if (logged_user()->isMemberOfOwnerCompany()) {
        $companies = Contacts::findAll(array("conditions" => "is_company = 1 AND object_id IN (SELECT company_id FROM " . TABLE_PREFIX . "contacts WHERE user_type>0 AND disabled=0)", 'order' => 'first_name'));
    } else {
        $companies = array(owner_company());
        if (logged_user()->getCompany() instanceof Contact) {
            $companies[] = logged_user()->getCompany();
        }
    }
    $allowed_object_types = array();
    $dim_obj_types = $dim->getAllowedObjectTypeContents();
    foreach ($dim_obj_types as $dim_obj_type) {
        // To draw a row for each object type of the dimension
        if (!array_key_exists($dim_obj_type->getContentObjectTypeId(), $allowed_object_types) && (!$member || $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId())) {
            $allowed_object_types[$dim_obj_type->getContentObjectTypeId()] = ObjectTypes::findById($dim_obj_type->getContentObjectTypeId());
            $allowed_object_types_json[] = $dim_obj_type->getContentObjectTypeId();
        }
    }
    $permission_groups = array();
    foreach ($companies as $company) {
        $users = $company->getUsersByCompany();
        foreach ($users as $u) {
            $permission_groups[] = $u->getPermissionGroupId();
        }
    }
    $no_company_users = Contacts::getAllUsers("AND `company_id` = 0", true);
    foreach ($no_company_users as $noc_user) {
        $permission_groups[] = $noc_user->getPermissionGroupId();
    }
    $non_personal_groups = PermissionGroups::getNonRolePermissionGroups();
    foreach ($non_personal_groups as $group) {
        $permission_groups[] = $group->getId();
    }
    $disabled_ots = array();
    $disableds = DB::executeAll("SELECT object_type_id FROM " . TABLE_PREFIX . "tab_panels WHERE object_type_id>0 AND enabled=0");
    if (is_array($disableds)) {
        $disabled_ots = array_flat($disableds);
    }
    $ws_ot = ObjectTypes::findByName('workspace')->getId();
    $disabled_ots[] = $ws_ot;
    $disabled_ot_cond = "";
    if (count($disabled_ots) > 0) {
        $disabled_ot_cond = "AND object_type_id NOT IN (" . implode(",", $disabled_ots) . ")";
    }
    foreach ($permission_groups as $pg_id) {
        if ($dim->hasAllowAllForContact($pg_id)) {
            $member_permissions[$pg_id] = array();
            foreach ($dim_obj_types as $dim_obj_type) {
                if ($member && $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) {
                    $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 1, 'd' => 1, 'r' => 1);
                } elseif (!$member) {
                    // WHEN CREATING a new member dont allow any user
                    $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 0, 'd' => 0, 'r' => 0);
                }
            }
        } else {
            if (!$dim->deniesAllForContact($pg_id)) {
                $member_permissions[$pg_id] = array();
                if ($member) {
                    $mpgs = ContactMemberPermissions::findAll(array("conditions" => array("`permission_group_id` = ? AND `member_id` = ? \r\n\t\t\t\t\t\t\tAND object_type_id IN (" . implode(',', $allowed_object_types_json) . ") {$disabled_ot_cond}", $pg_id, $member->getId())));
                    if (is_array($mpgs)) {
                        foreach ($mpgs as $mpg) {
                            $member_permissions[$mpg->getPermissionGroupId()][] = array('o' => $mpg->getObjectTypeId(), 'w' => $mpg->getCanWrite() ? 1 : 0, 'd' => $mpg->getCanDelete() ? 1 : 0, 'r' => 1);
                        }
                    }
                }
            }
        }
    }
    return array('member' => $member, 'allowed_object_types' => $allowed_object_types, 'allowed_object_types_json' => $allowed_object_types_json, 'permission_groups' => $permission_groups, 'member_permissions' => isset($member_permissions) ? $member_permissions : array());
}
Esempio n. 20
0
 /**
  * Execute search
  * TODO: Performance gus: 
  * Fetch only ids and execute a select statement by pk (fer each result)
  * @param void
  * @return null
  */
 function search()
 {
     // Init vars
     $search_for = array_var($_GET, 'search_for');
     $search_dimension = array_var($_GET, 'search_dimension');
     $advanced = array_var($_GET, 'advanced');
     $minWordLength = $this->minWordLength($search_for);
     $useLike = $minWordLength && $this->ignoreMinWordLength && $minWordLength < self::$MYSQL_MIN_WORD_LENGHT;
     $search_pieces = explode(" ", $search_for);
     $search_string = "";
     if (!$useLike) {
         // Prepare MATCH AGAINST string
         foreach ($search_pieces as $word) {
             if ((strpos($word, "@") || strpos($word, ".") || strpos($word, ",")) === false) {
                 // STRING Dont containt special characheters that mysql use as separator. Noramal  flow
                 if ($this->wildCardSearch) {
                     $word .= "*";
                 }
             } else {
                 $word = str_replace($this->mysqlWordSeparator, " +", $word);
             }
             if (!str_starts_with($word, " ")) {
                 $word = " +" . $word;
             }
             $search_string .= mysql_escape_string($word) . " ";
         }
         $search_string = substr($search_string, 0, -1);
     } else {
         // USE Like Query
         $search_string = mysql_escape_string($search_for);
     }
     $this->search_for = $search_for;
     $limit = $this->limit;
     $start = array_var($_REQUEST, 'start', $this->start);
     $this->start = $start;
     $limitTest = max($this->limitTest, $this->limit);
     $filteredResults = 0;
     $uid = logged_user()->getId();
     if (!isset($search_dimension)) {
         $members = active_context_members(false);
     } else {
         if ($search_dimension == 0) {
             $members = array();
         } else {
             $members = array($search_dimension);
         }
     }
     $members_sql = "";
     if (count($members) > 0) {
         $members_sql = "AND rel_object_id IN (SELECT object_id FROM " . TABLE_PREFIX . "object_members om WHERE member_id IN (" . implode(',', $members) . ")  \n                                    GROUP BY object_id\n                                    HAVING count(member_id) = " . count($members) . ")";
         $this->search_dimension = implode(',', $members);
     } else {
         $this->search_dimension = 0;
     }
     $revisionObjectTypeId = ObjectTypes::findByName("file revision")->getId();
     $listableObjectTypeIds = implode(",", ObjectTypes::getListableObjectTypeIds());
     if ($_POST) {
         $conditions = array_var($_POST, 'conditions');
         $search = array_var($_POST, 'search');
         $type_object = array_var($search, 'search_object_type_id');
         if (!is_array($conditions)) {
             $conditions = array();
         }
         $where_condiition = '';
         $conditions_view = array();
         $cont = 0;
         foreach ($conditions as $condition) {
             $condValue = array_key_exists('value', $condition) ? $condition['value'] : '';
             if ($condition['field_type'] == 'boolean') {
                 $value = array_key_exists('value', $condition);
             } else {
                 if ($condition['field_type'] == 'date') {
                     if ($condValue != '') {
                         $dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condValue);
                         $value = date("m/d/Y", $dtFromWidget->getTimestamp());
                     }
                 } else {
                     $value = $condValue;
                 }
             }
             if ($condition['condition'] == "like") {
                 $where_condiition .= " AND " . $condition['field_name'] . " " . $condition['condition'] . " '" . $value . "%' ";
             } else {
                 $where_condiition .= " AND " . $condition['field_name'] . " " . $condition['condition'] . " '" . $value . "' ";
             }
             $conditions_view[$cont]['id'] = $condition['id'];
             $conditions_view[$cont]['custom_property_id'] = $condition['custom_property_id'];
             $conditions_view[$cont]['field_name'] = $condition['field_name'];
             $conditions_view[$cont]['condition'] = $condition['condition'];
             $conditions_view[$cont]['value'] = $value;
             $cont++;
         }
         tpl_assign('conditions', $conditions_view);
         if ($type_object) {
             $object_table = ObjectTypes::findById($type_object);
             $table = $object_table->getTableName();
         }
         $sql = "\t\n\t\t\tSELECT  distinct(so.rel_object_id) AS id\n\t\t\tFROM " . TABLE_PREFIX . "searchable_objects so\n                        INNER JOIN  " . TABLE_PREFIX . $table . " nto ON nto.object_id = so.rel_object_id \n\t\t\tINNER JOIN  " . TABLE_PREFIX . "objects o ON o.id = so.rel_object_id \n\t\t\tWHERE (\n\t\t\t\t(\n\t\t\t\t\tso.rel_object_id IN (\n\t\t\t    \t\tSELECT object_id FROM " . TABLE_PREFIX . "sharing_table WHERE group_id  IN (\n\t\t\t      \t\t\tSELECT permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups WHERE contact_id = {$uid}\n\t\t\t    \t\t)\n\t\t\t \t\t)\n\t\t\t \t)\n\t\t\t) " . $where_condiition . $members_sql . " ORDER by o.updated_on DESC\n\t\t\tLIMIT {$start}, {$limitTest} ";
     } else {
         $type_object = '';
         $sql = "\t\n\t\t\tSELECT  distinct(so.rel_object_id) AS id\n\t\t\tFROM " . TABLE_PREFIX . "searchable_objects so\n\t\t\tINNER JOIN  " . TABLE_PREFIX . "objects o ON o.id = so.rel_object_id \n\t\t\tWHERE (\n\t\t\t\t(\t\n\t\t\t\t\to.object_type_id = {$revisionObjectTypeId} AND  \n\t\t\t\t\tEXISTS ( \n\t\t\t\t\t\tSELECT id FROM " . TABLE_PREFIX . "sharing_table WHERE object_id  = ( SELECT file_id FROM " . TABLE_PREFIX . "project_file_revisions WHERE object_id = o.id ) \n\t\t\t\t\t\tAND group_id IN (SELECT permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups WHERE contact_id = {$uid} )\n\t\t\t\t\t)\n\t\t\t\t\t\n\t\t\t\t) \n\t\t\t\tOR (\n\t\t\t\t\tso.rel_object_id IN (\n\t\t\t    \t\tSELECT object_id FROM " . TABLE_PREFIX . "sharing_table WHERE group_id  IN (\n\t\t\t      \t\t\tSELECT permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups WHERE contact_id = {$uid}\n\t\t\t    \t\t)\n\t\t\t \t\t)\n\t\t\t \t)\n\t\t\t)" . ($useLike ? "AND\tso.content LIKE '%{$search_string}%' " : "AND MATCH (so.content) AGAINST ('{$search_string}' IN BOOLEAN MODE) ") . " \n\t\t\tAND o.object_type_id IN ({$listableObjectTypeIds}) \n                        " . $members_sql . "\n\t\t\tORDER by o.updated_on DESC\n\t\t\tLIMIT {$start}, {$limitTest} ";
     }
     tpl_assign('type_object', $type_object);
     $db_search_results = array();
     $search_results_ids = array();
     $timeBegin = time();
     $res = DB::execute($sql);
     $timeEnd = time();
     if ($this->debug) {
         alert_r("<br>SQL:<br>" . $sql . "<hr>TIME:" . ($timeEnd - $timeBegin));
     }
     while ($row = $res->fetchRow()) {
         $search_results_ids[] = $row['id'];
     }
     // Prepare results for view to avoid processing at presentation layer
     $search_results = $this->prepareResults($search_results_ids, $null, $limit);
     // Calculate or approximate total for pagination
     $total = count($search_results_ids) + $start;
     if (count($search_results_ids) < $limitTest) {
         $total = count($search_results_ids) + $start;
     } else {
         $total = "Many";
     }
     //$total -= $filteredResults ;
     $this->total = $total;
     // Pagination
     $this->buildPagination($search_results);
     // Extra data
     $extra = new stdClass();
     if ($this->showQueryTime) {
         $extra->time = $timeEnd - $timeBegin;
     }
     //$extra->filteredResults = $filteredResults ;
     // Template asigns
     tpl_assign('pagination', $this->pagination);
     tpl_assign('search_string', $search_for);
     tpl_assign('search_dimension', $this->search_dimension);
     tpl_assign('search_results', $search_results);
     tpl_assign('advanced', $advanced);
     tpl_assign('extra', $extra);
     $types = array(array("", lang("select one")));
     $object_types = ObjectTypes::getAvailableObjectTypes();
     foreach ($object_types as $ot) {
         $types[] = array($ot->getId(), lang($ot->getName()));
     }
     //		if ($selected_type != '')
     //			tpl_assign('allowed_columns', $this->get_allowed_columns($selected_type));
     tpl_assign('object_types', $types);
     //		//Ajax
     if (!$total && !$advanced) {
         if ($_POST && count($search_results < 0)) {
             tpl_assign('msg_advanced', true);
         } else {
             $this->setTemplate('no_results');
         }
     }
     ajx_set_no_toolbar(true);
 }
Esempio n. 21
0
        }
    }
}
if ($show_widget) {
    $extra_conditions = " AND parent_member_id " . ($add_ctx_members && count($allowed_members) > 0 ? "IN (" . implode(",", $allowed_members) . ")" : "=0");
    $parent = null;
    $context = active_context();
    if (is_array($context)) {
        foreach ($context as $selection) {
            if ($selection instanceof Member && $selection->getDimensionId() == $ws_dimension->getId()) {
                $parent = $selection;
                break;
            }
        }
    }
    $ws_ot_id = ObjectTypes::findByName('workspace')->getId();
    $pg_array = logged_user()->getPermissionGroupIds();
    $current_member_cond = $parent instanceof Member ? "AND parent_member_id=" . $parent->getId() : "";
    $members = Members::findAll(array('limit' => $limit, 'order' => "depth, name", 'conditions' => "object_type_id={$ws_ot_id} {$current_member_cond} AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))"));
    if ($parent instanceof Member && count($members) < $limit) {
        $tmp_ids = array();
        foreach ($members as $m) {
            $tmp_ids[] = $m->getId();
        }
        $extra_conds = "AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))";
        $childs = $parent->getAllChildren(true, 'name', $extra_conds);
        foreach ($childs as $ch) {
            if (in_array($ch->getId(), $tmp_ids)) {
                continue;
            }
            if ($ch->getObjectTypeId() == $ws_ot_id && count($members) <= $limit) {
 private function get_allowed_columns($object_type)
 {
     $fields = array();
     if (isset($object_type)) {
         $customProperties = CustomProperties::getAllCustomPropertiesByObjectType($object_type);
         $objectFields = array();
         foreach ($customProperties as $cp) {
             if ($cp->getType() == 'table') {
                 continue;
             }
             $fields[] = array('id' => $cp->getId(), 'name' => $cp->getName(), 'type' => $cp->getType(), 'values' => $cp->getValues(), 'multiple' => $cp->getIsMultipleValues());
         }
         $ot = ObjectTypes::findById($object_type);
         if (class_exists($ot->getHandlerClass())) {
             eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();");
             $objectColumns = $managerInstance->getColumns();
         } else {
             $objectColumns = array();
         }
         $objectFields = array();
         if (class_exists($ot->getHandlerClass())) {
             $objectColumns = array_diff($objectColumns, $managerInstance->getSystemColumns());
             foreach ($objectColumns as $column) {
                 $objectFields[$column] = $managerInstance->getColumnType($column);
             }
         }
         $common_columns = Objects::instance()->getColumns(false);
         if (class_exists($ot->getHandlerClass())) {
             $common_columns = array_diff_key($common_columns, array_flip($managerInstance->getSystemColumns()));
         }
         $objectFields = array_merge($objectFields, $common_columns);
         foreach ($objectFields as $name => $type) {
             if ($type == DATA_TYPE_FLOAT || $type == DATA_TYPE_INTEGER) {
                 $type = 'numeric';
             } else {
                 if ($type == DATA_TYPE_STRING) {
                     $type = 'text';
                 } else {
                     if ($type == DATA_TYPE_BOOLEAN) {
                         $type = 'boolean';
                     } else {
                         if ($type == DATA_TYPE_DATE || $type == DATA_TYPE_DATETIME) {
                             $type = 'date';
                         }
                     }
                 }
             }
             $field_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $name);
             if (is_null($field_name)) {
                 $field_name = lang('field Objects ' . $name);
             }
             $fields_array = array('id' => $name, 'name' => $field_name, 'type' => $type);
             $task_ot = ObjectTypes::findByName('task');
             if ($task_ot instanceof ObjectType && $object_type == $task_ot->getId() && $name == 'priority') {
                 $fields_array = array('id' => 'priority', 'name' => lang('priority'), 'type' => 'list', 'values' => '100,200,300,400');
             }
             $fields[] = $fields_array;
         }
         if (class_exists($ot->getHandlerClass())) {
             $externalFields = $managerInstance->getExternalColumns();
             foreach ($externalFields as $extField) {
                 $field_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $extField);
                 if (is_null($field_name)) {
                     $field_name = lang('field Objects ' . $extField);
                 }
                 $fields[] = array('id' => $extField, 'name' => $field_name, 'type' => 'external', 'multiple' => 0);
             }
         }
         //if Object type is person
         $contact_ot = ObjectTypes::findByName('contact');
         if ($contact_ot instanceof ObjectType && $object_type == $contact_ot->getId()) {
             $fields[] = array('id' => 'is_user', 'name' => lang('is_user'), 'type' => 'boolean');
             $fields[] = array('id' => 'email_address', 'name' => lang('email address'), 'type' => 'text');
             $fields[] = array('id' => 'mobile_phone', 'name' => lang('mobile phone'), 'type' => 'text');
             $fields[] = array('id' => 'work_phone', 'name' => lang('work phone'), 'type' => 'text');
             $fields[] = array('id' => 'home_phone', 'name' => lang('home phone'), 'type' => 'text');
             $fields[] = array('id' => 'im_values', 'name' => lang('instant messaging'), 'type' => 'text');
             $fields[] = array('id' => 'personal_webpage', 'name' => lang('personal_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'work_webpage', 'name' => lang('work_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'other_webpage', 'name' => lang('other_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'home_address', 'name' => lang('home_address'), 'type' => 'text');
             $fields[] = array('id' => 'work_address', 'name' => lang('work_address'), 'type' => 'text');
             $fields[] = array('id' => 'other_address', 'name' => lang('other_address'), 'type' => 'text');
         }
         if (!array_var($_REQUEST, 'noaddcol')) {
             Hook::fire('custom_reports_additional_columns', array('object_type' => $ot), $fields);
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }