3 * Table Definition for Person
5 require_once 'DB/DataObject.php';
8 class Pman_Core_DataObjects_Person extends DB_DataObject
11 /* the code below is auto generated do not remove the above tag */
13 public $__table = 'Person'; // table name
14 public $id; // int(11) not_null primary_key auto_increment
15 public $email; // string(128) not_null
18 public $company_id; // int(11)
19 public $office_id; // int(11)
20 public $name; // string(128) not_null
21 public $firstname; // string(128) not_null
22 public $lastname; // string(128) not_null
23 public $phone; // string(32) not_null
24 public $fax; // string(32) not_null
26 public $role; // string(32) not_null
27 public $remarks; // blob(65535) not_null blob
28 public $passwd; // string(64) not_null
29 public $owner_id; // int(11) not_null
30 public $lang; // string(8)
31 public $no_reset_sent; // int(11)
32 public $action_type; // string(32)
33 public $project_id; // int(11)
36 public $active; // int(11) not_null
37 public $deleted_by; // int(11) not_null
38 public $deleted_dt; // datetime(19) binary
41 public $name_facebook; // VARCHAR(128) NULL;
42 public $url_blog; // VARCHAR(256) NULL ;
43 public $url_twitter; // VARCHAR(256) NULL ;
44 public $url_linkedin; // VARCHAR(256) NULL ;
46 public $phone_mobile; // varchar(32) NOT NULL DEFAULT '';
47 public $phone_direct; // varchar(32) NOT NULL DEFAULT '';
49 /* the code above is auto generated do not remove the tag below */
54 $p = DB_DataObject::Factory('Person');
55 $p->get($this->owner_id);
64 * FIXME !!!! -- USE Pman_Core_Mailer !!!!!
70 function buildMail($templateFile, $args)
73 $args = (array) $args;
74 $content = clone($this);
76 foreach((array)$args as $k=>$v) {
80 $ff = HTML_FlexyFramework::get();
83 //?? is this really the place for this???
86 empty($args['no_auth']) &&
87 !in_array($templateFile, array(
88 // templates that can be sent without authentication.
94 $content->authUser = $this->getAuthUser();
95 if (!$content->authUser) {
96 return PEAR::raiseError("Not authenticated");
100 // should handle x-forwarded...
102 $content->HTTP_HOST = isset($_SERVER["HTTP_HOST"]) ?
103 $_SERVER["HTTP_HOST"] :
104 (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost');
106 /* use the regex compiler, as it doesnt parse <tags */
109 'compiler' => 'Flexy',
111 'filters' => array('SimpleTags','Mail'),
117 if (!empty($args['templateDir'])) {
118 $tops['templateDir'] = $args['templateDir'];
123 require_once 'HTML/Template/Flexy.php';
124 $template = new HTML_Template_Flexy( $tops );
125 $template->compile("mail/$templateFile.txt");
127 /* use variables from this object to ouput data. */
128 $mailtext = $template->bufferedOutputObject($content);
131 // if a html file with the same name exists, use that as the body
132 // I've no idea where this code went, it was here before..
133 if (false !== $template->resolvePath ( "mail/$templateFile.html" )) {
134 $tops['nonHTML'] = false;
135 $template = new HTML_Template_Flexy( $tops );
136 $template->compile("mail/$templateFile.html");
137 $htmlbody = $template->bufferedOutputObject($content);
143 //echo "<PRE>";print_R($mailtext);
144 //print_R($mailtext);exit;
145 /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
146 require_once 'Mail/mimeDecode.php';
147 require_once 'Mail.php';
149 $decoder = new Mail_mimeDecode($mailtext);
150 $parts = $decoder->getSendArray();
152 if (PEAR::isError($parts)) {
154 //echo "PROBLEM: {$parts->message}";
157 list($recipents,$headers,$body) = $parts;
158 $recipents = array($this->email);
159 if (!empty($content->bcc) && is_array($content->bcc)) {
160 $recipents =array_merge($recipents, $content->bcc);
162 $headers['Date'] = date('r');
164 if ($htmlbody !== false) {
165 require_once 'Mail/mime.php';
166 $mime = new Mail_mime(array('eol' => "\n"));
167 $mime->setTXTBody($body);
168 $mime->setHTMLBody($htmlbody);
169 // I think there might be code in mediaoutreach toEmail somewhere
170 // h embeds images here..
171 $body = $mime->get();
172 $headers = $mime->headers($headers);
179 'recipients' => $recipents,
180 'headers' => $headers,
190 * - user must be authenticate or args[no_auth] = true
191 * or template = password_[reset|welcome]
194 function sendTemplate($templateFile, $args)
197 $ar = $this->buildMail($templateFile, $args);
200 //print_r($recipents);exit;
201 $mailOptions = PEAR::getStaticProperty('Mail','options');
202 $mail = Mail::factory("SMTP",$mailOptions);
204 if (PEAR::isError($mail)) {
207 $oe = error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
208 $ret = $mail->send($ar['recipients'],$ar['headers'],$ar['body']);
209 error_reporting($oe);
218 function getEmailFrom()
220 return '"' . addslashes($this->name) . '" <' . $this->email . '>';
222 function toEventString()
224 return empty($this->name) ? $this->email : $this->name;
226 function verifyAuth()
228 $ff= HTML_FlexyFramework::get();
229 if (!empty($ff->Pman['auth_comptype']) &&
230 (!$this->company_id || ($ff->Pman['auth_comptype'] != $this->company()->comptype))
233 // force a logout - without a check on the isAuth - as this is called from there..
234 $db = $this->getDatabaseConnection();
235 $sesPrefix = $ff->appNameShort .'-'.get_class($this) .'-'.$db->dsn['database'] ;
236 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
239 $ff->page->jerr("Login not permited to outside companies");
246 // ---------------- authentication / passwords and keys stuff ----------------
249 $db = $this->getDatabaseConnection();
250 // we combine db + project names,
251 // otherwise if projects use different 'auth' objects
252 // then we get unserialize issues.
253 $ff= HTML_FlexyFramework::get();
254 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
259 if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
261 $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
263 $u = DB_DataObject::factory('Person');
264 if ($u->get($a->id)) { //&& strlen($u->passwd)) {
266 return $u->verifyAuth();
272 unset($_SESSION[__CLASS__][$sesPrefix .'-auth']);
276 $default_admin = false;
277 if (!empty($ff->Pman['local_autoauth']) &&
278 ($ff->Pman['local_autoauth'] === true) &&
279 (!empty($_SERVER['SERVER_ADDR'])) &&
280 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
281 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
283 $group = DB_DataObject::factory('Groups');
284 $group->get('name', 'Administrators');
286 $member = DB_DataObject::factory('group_members');
288 $member->group_id = $group->id;
290 join_user_id_id.id IS NOT NULL
292 if($member->find(true)){
293 $default_admin = DB_DataObject::factory('Person');
294 if(!$default_admin->get($member->user_id)){
295 $default_admin = false;
301 $u = DB_DataObject::factory('Person');
302 $ff = HTML_FlexyFramework::get();
303 if (!empty($ff->Pman['local_autoauth']) &&
304 (!empty($_SERVER['SERVER_ADDR'])) &&
305 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
306 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') &&
307 ($default_admin || $u->get('email', $ff->Pman['local_autoauth']))
309 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($default_admin ? $default_admin : $u);
314 $u = DB_DataObject::factory('Person');
316 if (!empty($_SERVER['PHP_AUTH_USER'])
318 !empty($_SERVER['PHP_AUTH_PW'])
320 $u->get('email', $_SERVER['PHP_AUTH_USER'])
322 $u->checkPassword($_SERVER['PHP_AUTH_PW'])
324 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($u);
327 //var_dump(session_id());
328 //var_dump($_SESSION[__CLASS__]);
330 //if (!empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
333 //die("got this far?");
334 // not in session or not matched...
335 $u = DB_DataObject::factory('Person');
336 $u->whereAdd(' LENGTH(passwd) > 0');
338 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $n;
339 $error = PEAR::getStaticProperty('DB_DataObject','lastError');
341 die($error->toString()); // not really a good thing to do...
343 if (!$n){ // authenticated as there are no users in the system...
350 function getAuthUser()
352 if (!$this->isAuth()) {
355 $db = $this->getDatabaseConnection();
357 $ff= HTML_FlexyFramework::get();
358 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
362 if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
363 $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
365 $u = DB_DataObject::factory('Person');
366 if ($u->get($a->id)) { /// && strlen($u->passwd)) {
369 unset($_SESSION[__CLASS__][$sesPrefix .'-auth']);
372 if (empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
373 $u = DB_DataObject::factory('Person');
374 $u->whereAdd(' LENGTH(passwd) > 0');
375 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $u->count();
379 if (isset( $_SESSION[__CLASS__][$sesPrefix .'-empty'] ) && $_SESSION[__CLASS__][$sesPrefix .'-empty'] < 1) {
381 // fake person - open system..
382 //$ce = DB_DataObject::factory('core_enum');
386 $u = DB_DataObject::factory('Person');
389 // if a company has been created fill that in in company_id_id
390 $c = DB_DAtaObject::factory('Companies')->lookupOwner();
392 $u->company_id_id = $c->pid();
393 $u->company_id = $c->pid();
403 $this->isAuth(); // force session start..
404 if (!$this->verifyAuth()) {
407 $db = $this->getDatabaseConnection();
410 // open up iptables at login..
411 $dbname = $this->database();
412 touch( '/tmp/run_pman_admin_iptables-'.$dbname);
414 // refresh admin group if we are logged in as one..
415 //DB_DataObject::debugLevel(1);
416 $g = DB_DataObject::factory('Groups');
418 $g->get('name', 'Administrators');
419 $gm = DB_DataObject::Factory('group_members');
420 if (in_array($g->id,$gm->listGroupMembership($this))) {
421 // refresh admin groups.
422 $gr = DB_DataObject::Factory('group_rights');
423 $gr->applyDefs($g, 0);
425 $ff= HTML_FlexyFramework::get();
426 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
429 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($this);
434 $this->isAuth(); // force session start..
435 $db = $this->getDatabaseConnection();
436 $ff= HTML_FlexyFramework::get();
437 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
439 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
445 function genPassKey ($t)
447 return md5($this->email . $t. $this->passwd);
449 function simpleAuthKey($m = 0)
451 $month = $m > -1 ? date('Y-m') : date('Y-m', strtotime('LAST MONTH'));
453 return md5(implode(',' , array($month, $this->email , $this->passwd, $this->id)));
455 function checkPassword($val)
458 if (substr($this->passwd,0,1) == '$') {
459 return crypt($val,$this->passwd) == $this->passwd ;
461 // old style md5 passwords...- cant be used with courier....
462 return md5($val) == $this->passwd;
464 function setPassword($value)
467 while(strlen($salt)<9) {
468 $salt.=chr(rand(64,126));
469 //php -r var_dump(crypt('testpassword', '$1$'. (rand(64,126)). '$'));
471 $this->passwd = crypt($value, '$1$'. $salt. '$');
476 function generatePassword() // genearte a password (add set 'rawPasswd' to it's value)
478 require_once 'Text/Password.php';
479 $this->rawPasswd = strtr(ucfirst(Text_Password::create(5)).ucfirst(Text_Password::create(5)), array(
480 "a"=>"4", "e"=>"3", "i"=>"1", "o"=>"0", "s"=>"5", "t"=>"7"));
481 $this->setPassword($this->rawPasswd);
482 return $this->rawPasswd;
487 $x = DB_DataObject::factory('Companies');
489 $x->get($this->company_id);
492 function loadCompany()
494 $this->company = $this->company();
499 return $this->active;
501 function authUserName($n) // set username prior to acheck user exists query.
504 $this->whereAdd('LENGTH(passwd) > 1');
509 if (!func_num_args()) {
512 $val = array_shift(func_get_args());
513 if ($val == $this->lang) {
523 function authUserArray()
526 $aur = $this->toArray();
533 //DB_DataObject::debugLevel(1);
534 $c = DB_Dataobject::factory('Companies');
535 $im = DB_Dataobject::factory('Images');
536 $c->joinAdd($im, 'LEFT');
538 $c->selectAs($c, 'company_id_%s');
539 $c->selectAs($im, 'company_id_logo_id_%s');
540 $c->id = $this->company_id;
544 $aur = array_merge( $c->toArray(),$aur);
546 if (empty($c->company_id_logo_id_id)) {
548 $im = DB_Dataobject::factory('Images');
549 $im->ontable = 'Companies';
551 $im->imgtype = 'LOGO';
554 $im->selectAs($im, 'company_id_logo_id_%s');
555 if ($im->find(true)) {
557 foreach($im->toArray() as $k=>$v) {
564 $aur['perms'] = $this->getPerms();
565 $g = DB_DataObject::Factory('group_members');
566 $aur['groups'] = $g->listGroupMembership($this, 'name');
569 $aur['dailykey'] = '';
576 // ----------PERMS------ ----------------
579 //DB_DataObject::debugLevel(1);
580 // find out all the groups they are a member of.. + Default..
582 // ------ INIITIALIZE IF NO GROUPS ARE SET UP.
584 $g = DB_DataObject::Factory('group_rights');
590 return $g->adminRights(); // system is not set up - so they get full rights.
592 //DB_DataObject::debugLevel(1);
593 $g = DB_DataObject::Factory('group_members');
594 $g->whereAdd('group_id is NOT NULL AND user_id IS NOT NULL');
596 // add the current user to the admin group..
597 $g = DB_DataObject::Factory('Groups');
598 if ($g->get('name', 'Administrators')) {
599 $gm = DB_DataObject::Factory('group_members');
600 $gm->group_id = $g->id;
601 $gm->user_id = $this->id;
607 // ------ STANDARD PERMISSION HANDLING.
608 $isOwner = $this->company()->comptype == 'OWNER';
609 $g = DB_DataObject::Factory('group_members');
610 $grps = $g->listGroupMembership($this);
612 $isAdmin = $g->inAdmin;
613 //echo '<PRE>'; print_r($grps);var_dump($isAdmin);
614 // the load all the perms for those groups, and add them all together..
615 // then load all those
616 $g = DB_DataObject::Factory('group_rights');
617 $ret = $g->listPermsFromGroupIds($grps, $isAdmin, $isOwner);
618 //echo '<PRE>';print_r($ret);
624 *Basic group fetching - probably needs to filter by type eventually.
626 *@param String $what - fetchall() argument - eg. 'name' returns names of all groups that they are members of.
629 function groups($what=false)
631 $g = DB_DataObject::Factory('group_members');
632 $grps = $g->listGroupMembership($this);
633 $g = DB_DataObject::Factory('Groups');
634 $g->whereAddIn('id', $grps, 'int');
635 return $g->fetchAll($what);
641 function hasPerm($name, $lvl)
643 static $pcache = array();
645 if (!isset($pcache[$this->id])) {
646 $pcache[$this->id] = $this->getPerms();
648 // echo "<PRE>";print_r($pcache[$au->id]);
649 // var_dump($pcache[$au->id]);
650 if (empty($pcache[$this->id][$name])) {
654 return strpos($pcache[$this->id][$name], $lvl) > -1;
658 // ------------ROO HOOKS------------------------------------
659 function applyFilters($q, $au, $roo)
661 //DB_DataObject::DebugLevel(1);
662 if (!empty($q['query']['person_not_internal'])) {
663 $this->whereAdd(" join_company_id_id.isOwner = 0 ");
667 if (!empty($q['query']['person_internal_only_all'])) {
670 // must be internal and not current user (need for distribution list)
671 // user has a projectdirectory entry and role is not blank.
672 //DB_DataObject::DebugLevel(1);
673 $pd = DB_DataObject::factory('ProjectDirectory');
674 $pd->whereAdd("role != ''");
676 $pd->selectAdd('distinct(person_id) as person_id');
677 $roled = $pd->fetchAll('person_id');
679 {$this->tableName()}.id IN (".implode(',', $roled) . ")
681 $this->whereAdd(" join_company_id_id.comptype = 'OWNER' $rs ");
684 // -- for distribution
685 if (!empty($q['query']['person_internal_only'])) {
686 // must be internal and not current user (need for distribution list)
687 $this->whereAdd(" join_company_id_id.comptype = 'OWNER'");
689 //$this->whereAdd(($this->tableName() == 'Person' ? 'Person' : "join_person_id_id") .
690 // ".id != ".$au->id);
691 $this->whereAdd("Person.id != {$au->id}");
694 if (!empty($q['query']['comptype_or_company_id'])) {
695 // DB_DataObject::debugLevel(1);
696 $bits = explode(',', $q['query']['comptype_or_company_id']);
697 $id = (int) array_pop($bits);
698 $ct = $this->escape($bits[0]);
700 $this->whereAdd(" join_company_id_id.comptype = '$ct' OR Person.company_id = $id");
706 if (!empty($q['query']['person_inactive'])) {
707 // DB_Dataobject::debugLevel(1);
710 $tn_p = $this->tableName();
711 $tn_gm = DB_DataObject::Factory('group_members')->tableName();
712 $tn_g = DB_DataObject::Factory('Groups')->tableName();
714 ///---------------- Group views --------
715 if (!empty($q['query']['in_group'])) {
716 // DB_DataObject::debugLevel(1);
717 $ing = (int) $q['query']['in_group'];
718 if ($q['query']['in_group'] == -1) {
720 // list all staff who are not in a group.
721 $this->whereAdd("Person.id NOT IN (
722 SELECT distinct(user_id) FROM $tn_gm LEFT JOIN
723 $tn_g ON $tn_g.id = $tn_gm.group_id
724 WHERE $tn_g.type = ".$q['query']['type']."
730 $this->whereAdd("$tn_p.id IN (
731 SELECT distinct(user_id) FROM $tn_gm
732 WHERE group_id = $ing
738 if (!empty($q['query']['not_in_directory'])) {
739 // it's a Person list..
740 // DB_DATaobjecT::debugLevel(1);
742 // specific to project directory which is single comp. login
744 $owncomp = DB_DataObject::Factory('Companies');
745 $owncomp->get('comptype', 'OWNER');
746 if ($q['company_id'] == $owncomp->id) {
752 if ( $q['query']['not_in_directory'] > -1) {
753 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
754 // can list current - so that it does not break!!!
755 $this->whereAdd("$tn_p.id NOT IN
756 ( SELECT distinct person_id FROM $tn_pd WHERE
757 project_id = " . $q['query']['not_in_directory'] . " AND
758 company_id = " . $this->company_id . ')');
762 if (!empty($q['query']['role'])) {
763 // it's a Person list..
764 // DB_DATaobjecT::debugLevel(1);
766 // specific to project directory which is single comp. login
768 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
769 // can list current - so that it does not break!!!
770 $this->whereAdd("$tn_p.id IN
771 ( SELECT distinct person_id FROM $tn_pd WHERE
772 role = '". $this->escape($q['query']['role']) ."'
778 if (!empty($q['query']['project_member_of'])) {
779 // this is also a flag to return if they are a member..
780 //DB_DataObject::debugLevel(1);
781 $do = DB_DataObject::factory('ProjectDirectory');
782 $do->project_id = $q['query']['project_member_of'];
783 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
784 $this->joinAdd($do,array('joinType' => 'LEFT', 'useWhereAsOn' => true));
785 $this->selectAdd("IF($tn_pd.id IS NULL, 0, $tn_pd.id ) as is_member");
788 if (!empty($q['query']['project_member_filter'])) {
789 $this->having('is_member !=0');
795 if(!empty($q['query']['name'])){
797 Person.name LIKE '%{$this->escape($q['query']['name'])}%'
801 if (!empty($q['query']['search'])) {
803 // use our magic search builder...
805 require_once 'Text/SearchParser.php';
806 $x = new Text_SearchParser($q['query']['search']);
814 "join_company_id_id.name"
817 $str = $x->toSQL(array(
820 'company' => 'join_company_id_id.name',
821 //'country' => 'Clipping.country',
822 // 'media' => 'Clipping.media_name',
824 'escape' => array($this->getDatabaseConnection(), 'escapeSimple'), /// pear db or mdb object..
829 $this->whereAdd($str); /*
830 $tn_p.name LIKE '%$s%' OR
831 $tn_p.email LIKE '%$s%' OR
832 $tn_p.role LIKE '%$s%' OR
833 $tn_p.phone LIKE '%$s%' OR
834 $tn_p.remarks LIKE '%$s%'
841 function setFromRoo($ar, $roo)
844 if (!empty($ar['passwd1'])) {
845 $this->setPassword($ar['passwd1']);
850 ($this->email == $roo->old->email)&&
851 ($this->company_id == $roo->old->company_id)
855 if (empty($this->email)) {
858 $xx = DB_Dataobject::factory('Person');
860 'email' => $this->email,
861 // 'company_id' => $x->company_id
865 return "Duplicate Email found";
871 * before Delete - delete significant dependancies..
872 * this is called after checkPerm..
875 function beforeDelete()
878 $e = DB_DataObject::Factory('Events');
879 $e->whereAdd('person_id = ' . $this->id);
888 * Check if the a user has access to modify this item.
889 * @param String $lvl Level (eg. Core.Projects)
890 * @param Pman_Core_DataObjects_Person $au The authenticated user.
891 * @param boolean $changes alllow changes???
893 * @return false if no access..
895 function checkPerm($lvl, $au, $changes=false) //heck who is trying to access this. false == access denied..
898 // do we have an empty system..
899 if ($au && $au->id == -1) {
903 // determine if it's staff!!!
905 if ($au->company()->comptype != 'OWNER') {
907 // - can not change company!!!
909 isset($changes['company_id']) &&
910 $changes['company_id'] != $au->company_id) {
913 // can only set new emails..
915 !empty($this->email) &&
916 isset($changes['email']) &&
917 $changes['email'] != $this->email) {
921 // edit self... - what about other staff members...
923 return $this->company_id == $au->company_id;
927 // yes, only owner company can mess with this...
928 $owncomp = DB_DataObject::Factory('Companies');
929 $owncomp->get('comptype', 'OWNER');
931 $isStaff = ($this->company_id == $owncomp->id);
935 // extra case change passwod?
936 case 'P': //??? password
937 // standard perms -- for editing + if the user is dowing them selves..
938 $ret = $isStaff ? $au->hasPerm("Core.Staff", "E") : $au->hasPerm("Core.Person", "E");
939 return $ret || $au->id == $this->id;
942 return $isStaff ? $au->hasPerm("Core.Staff", $lvl) : $au->hasPerm("Core.Person", $lvl);
947 function onInsert($req, $roo)
950 $p = DB_DataObject::factory('person');
951 if ($roo->authUser->id < 0 && $p->count() == 1) {
952 // this seems a bit risky...
954 $g = DB_DataObject::factory('Groups');
958 $g->get('name', 'Administrators');
960 $p = DB_DataObject::factory('group_members');
961 $p->group_id = $g->id;
962 $p->user_id = $this->id;
965 $roo->addEvent("ADD", $p, $g->toEventString(). " Added " . $this->toEventString());
969 if (!empty($req['project_id_addto'])) {
970 $pd = DB_DataObject::factory('ProjectDirectory');
971 $pd->project_id = $req['project_id_addto'];
972 $pd->person_id = $this->id;
974 $pd->office_id = $this->office_id;
975 $pd->company_id = $this->company_id;
981 function importFromArray($roo, $persons, $opts)
983 if (empty($opts['prefix'])) {
984 $roo->jerr("opts[prefix] is empty - you can not just create passwords based on the user names");
987 if (!is_array($persons) || empty($persons)) {
988 $roo->jerr("error in the person data. - empty on not valid");
990 DB_DataObject::factory('groups')->initGroups();
992 foreach($persons as $person){
993 $p = DB_DataObject::factory('person');
994 if($p->get('name', $person['name'])){
997 $p->setFrom($person);
999 $companies = DB_DataObject::factory('companies');
1000 if(!$companies->get('comptype', 'OWNER')){
1001 $roo->jerr("Missing OWNER companies!");
1003 $p->company_id = $companies->pid();
1004 // strip the 'spaces etc.. make lowercase..
1005 $name = strtolower(str_replace(' ', '', $person['name']));
1006 $p->setPassword("{$opts['prefix']}{$name}");
1009 // if $person->groups is set.. then
1010 // add this person to that group eg. groups : [ 'Administrator' ]
1011 if(!empty($person['groups'])){
1012 $groups = DB_DataObject::factory('groups');
1013 if(!$groups->get('name', $person['groups'])){
1014 $roo->jerr("Missing groups : {$person['groups']}");
1016 $gm = DB_DataObject::factory('group_members');
1017 $gm->change($p, $groups, true);
1020 $p->onInsert(array(), $roo);