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 ;
45 public $linkedin_id; // VARCHAR(256) NULL ;
47 public $phone_mobile; // varchar(32) NOT NULL DEFAULT '';
48 public $phone_direct; // varchar(32) NOT NULL DEFAULT '';
49 public $countries; // VARCHAR(128) NULL;
51 /* the code above is auto generated do not remove the tag below */
56 $p = DB_DataObject::Factory('Person');
57 $p->get($this->owner_id);
66 * FIXME !!!! -- USE Pman_Core_Mailer !!!!!
72 function buildMail($templateFile, $args)
75 $args = (array) $args;
76 $content = clone($this);
78 foreach((array)$args as $k=>$v) {
82 $ff = HTML_FlexyFramework::get();
85 //?? is this really the place for this???
88 empty($args['no_auth']) &&
89 !in_array($templateFile, array(
90 // templates that can be sent without authentication.
96 $content->authUser = $this->getAuthUser();
97 if (!$content->authUser) {
98 return PEAR::raiseError("Not authenticated");
102 // should handle x-forwarded...
104 $content->HTTP_HOST = isset($_SERVER["HTTP_HOST"]) ?
105 $_SERVER["HTTP_HOST"] :
106 (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost');
108 /* use the regex compiler, as it doesnt parse <tags */
111 'compiler' => 'Flexy',
113 'filters' => array('SimpleTags','Mail'),
119 if (!empty($args['templateDir'])) {
120 $tops['templateDir'] = $args['templateDir'];
125 require_once 'HTML/Template/Flexy.php';
126 $template = new HTML_Template_Flexy( $tops );
127 $template->compile("mail/$templateFile.txt");
129 /* use variables from this object to ouput data. */
130 $mailtext = $template->bufferedOutputObject($content);
133 // if a html file with the same name exists, use that as the body
134 // I've no idea where this code went, it was here before..
135 if (false !== $template->resolvePath ( "mail/$templateFile.html" )) {
136 $tops['nonHTML'] = false;
137 $template = new HTML_Template_Flexy( $tops );
138 $template->compile("mail/$templateFile.html");
139 $htmlbody = $template->bufferedOutputObject($content);
145 //echo "<PRE>";print_R($mailtext);
146 //print_R($mailtext);exit;
147 /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
148 require_once 'Mail/mimeDecode.php';
149 require_once 'Mail.php';
151 $decoder = new Mail_mimeDecode($mailtext);
152 $parts = $decoder->getSendArray();
154 if (PEAR::isError($parts)) {
156 //echo "PROBLEM: {$parts->message}";
159 list($recipents,$headers,$body) = $parts;
160 $recipents = array($this->email);
161 if (!empty($content->bcc) && is_array($content->bcc)) {
162 $recipents =array_merge($recipents, $content->bcc);
164 $headers['Date'] = date('r');
166 if ($htmlbody !== false) {
167 require_once 'Mail/mime.php';
168 $mime = new Mail_mime(array('eol' => "\n"));
169 $mime->setTXTBody($body);
170 $mime->setHTMLBody($htmlbody);
171 // I think there might be code in mediaoutreach toEmail somewhere
172 // h embeds images here..
173 $body = $mime->get();
174 $headers = $mime->headers($headers);
181 'recipients' => $recipents,
182 'headers' => $headers,
192 * - user must be authenticate or args[no_auth] = true
193 * or template = password_[reset|welcome]
196 function sendTemplate($templateFile, $args)
199 $ar = $this->buildMail($templateFile, $args);
202 //print_r($recipents);exit;
203 $mailOptions = PEAR::getStaticProperty('Mail','options');
204 $mail = Mail::factory("SMTP",$mailOptions);
206 if (PEAR::isError($mail)) {
209 $oe = error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
210 $ret = $mail->send($ar['recipients'],$ar['headers'],$ar['body']);
211 error_reporting($oe);
220 function getEmailFrom()
222 if (empty($this->name)) {
225 return '"' . addslashes($this->name) . '" <' . $this->email . '>';
228 function toEventString()
230 return empty($this->name) ? $this->email : $this->name;
233 function verifyAuth()
235 $ff= HTML_FlexyFramework::get();
236 if (!empty($ff->Pman['auth_comptype']) &&
237 (!$this->company_id || ($ff->Pman['auth_comptype'] != $this->company()->comptype))
240 // force a logout - without a check on the isAuth - as this is called from there..
241 $db = $this->getDatabaseConnection();
242 $sesPrefix = $ff->appNameShort .'-'.get_class($this) .'-'.$db->dsn['database'] ;
243 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
246 $ff->page->jerr("Login not permited to outside companies");
253 // ---------------- authentication / passwords and keys stuff ----------------
256 $db = $this->getDatabaseConnection();
257 // we combine db + project names,
258 // otherwise if projects use different 'auth' objects
259 // then we get unserialize issues.
260 $ff= HTML_FlexyFramework::get();
261 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
266 if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
268 $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
270 $u = DB_DataObject::factory('Person');
271 if ($u->get($a->id)) { //&& strlen($u->passwd)) {
273 return $u->verifyAuth();
279 unset($_SESSION[__CLASS__][$sesPrefix .'-auth']);
283 $default_admin = false;
284 if (!empty($ff->Pman['local_autoauth']) &&
285 ($ff->Pman['local_autoauth'] === true) &&
286 (!empty($_SERVER['SERVER_ADDR'])) &&
287 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
288 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
290 $group = DB_DataObject::factory('Groups');
291 $group->get('name', 'Administrators');
293 $member = DB_DataObject::factory('group_members');
295 $member->group_id = $group->id;
297 join_user_id_id.id IS NOT NULL
299 if($member->find(true)){
300 $default_admin = DB_DataObject::factory('Person');
301 if(!$default_admin->get($member->user_id)){
302 $default_admin = false;
308 $u = DB_DataObject::factory('Person');
309 $ff = HTML_FlexyFramework::get();
310 if (!empty($ff->Pman['local_autoauth']) &&
311 (!empty($_SERVER['SERVER_ADDR'])) &&
312 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
313 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') &&
314 ($default_admin || $u->get('email', $ff->Pman['local_autoauth']))
316 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($default_admin ? $default_admin : $u);
321 $u = DB_DataObject::factory('Person');
323 if (!empty($_SERVER['PHP_AUTH_USER'])
325 !empty($_SERVER['PHP_AUTH_PW'])
327 $u->get('email', $_SERVER['PHP_AUTH_USER'])
329 $u->checkPassword($_SERVER['PHP_AUTH_PW'])
331 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($u);
334 //var_dump(session_id());
335 //var_dump($_SESSION[__CLASS__]);
337 //if (!empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
340 //die("got this far?");
341 // not in session or not matched...
342 $u = DB_DataObject::factory('Person');
343 $u->whereAdd(' LENGTH(passwd) > 0');
345 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $n;
346 $error = PEAR::getStaticProperty('DB_DataObject','lastError');
348 die($error->toString()); // not really a good thing to do...
350 if (!$n){ // authenticated as there are no users in the system...
357 function getAuthUser()
359 if (!$this->isAuth()) {
362 $db = $this->getDatabaseConnection();
364 $ff= HTML_FlexyFramework::get();
365 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
369 if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
370 $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
372 $u = DB_DataObject::factory('Person');
373 if ($u->get($a->id)) { /// && strlen($u->passwd)) {
376 unset($_SESSION[__CLASS__][$sesPrefix .'-auth']);
379 if (empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
380 $u = DB_DataObject::factory('Person');
381 $u->whereAdd(' LENGTH(passwd) > 0');
382 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $u->count();
386 if (isset( $_SESSION[__CLASS__][$sesPrefix .'-empty'] ) && $_SESSION[__CLASS__][$sesPrefix .'-empty'] < 1) {
388 // fake person - open system..
389 //$ce = DB_DataObject::factory('core_enum');
393 $u = DB_DataObject::factory('Person');
396 // if a company has been created fill that in in company_id_id
397 $c = DB_DAtaObject::factory('Companies')->lookupOwner();
399 $u->company_id_id = $c->pid();
400 $u->company_id = $c->pid();
410 $this->isAuth(); // force session start..
411 if (!$this->verifyAuth()) {
414 $db = $this->getDatabaseConnection();
417 // open up iptables at login..
418 $dbname = $this->database();
419 touch( '/tmp/run_pman_admin_iptables-'.$dbname);
421 // refresh admin group if we are logged in as one..
422 //DB_DataObject::debugLevel(1);
423 $g = DB_DataObject::factory('Groups');
425 $g->get('name', 'Administrators');
426 $gm = DB_DataObject::Factory('group_members');
427 if (in_array($g->id,$gm->listGroupMembership($this))) {
428 // refresh admin groups.
429 $gr = DB_DataObject::Factory('group_rights');
430 $gr->applyDefs($g, 0);
432 $ff= HTML_FlexyFramework::get();
433 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
436 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($this);
441 $this->isAuth(); // force session start..
442 $db = $this->getDatabaseConnection();
443 $ff= HTML_FlexyFramework::get();
444 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
446 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
452 function genPassKey ($t)
454 return md5($this->email . $t. $this->passwd);
456 function simpleAuthKey($m = 0)
458 $month = $m > -1 ? date('Y-m') : date('Y-m', strtotime('LAST MONTH'));
460 return md5(implode(',' , array($month, $this->email , $this->passwd, $this->id)));
462 function checkPassword($val)
465 if (substr($this->passwd,0,1) == '$') {
466 return crypt($val,$this->passwd) == $this->passwd ;
468 // old style md5 passwords...- cant be used with courier....
469 return md5($val) == $this->passwd;
471 function setPassword($value)
474 while(strlen($salt)<9) {
475 $salt.=chr(rand(64,126));
476 //php -r var_dump(crypt('testpassword', '$1$'. (rand(64,126)). '$'));
478 $this->passwd = crypt($value, '$1$'. $salt. '$');
483 function generatePassword() // genearte a password (add set 'rawPasswd' to it's value)
485 require_once 'Text/Password.php';
486 $this->rawPasswd = strtr(ucfirst(Text_Password::create(5)).ucfirst(Text_Password::create(5)), array(
487 "a"=>"4", "e"=>"3", "i"=>"1", "o"=>"0", "s"=>"5", "t"=>"7"));
488 $this->setPassword($this->rawPasswd);
489 return $this->rawPasswd;
494 $x = DB_DataObject::factory('Companies');
496 $x->get($this->company_id);
499 function loadCompany()
501 $this->company = $this->company();
506 return $this->active;
508 function authUserName($n) // set username prior to acheck user exists query.
511 $this->whereAdd('LENGTH(passwd) > 1');
516 if (!func_num_args()) {
519 $val = array_shift(func_get_args());
520 if ($val == $this->lang) {
530 function authUserArray()
533 $aur = $this->toArray();
540 //DB_DataObject::debugLevel(1);
541 $c = DB_Dataobject::factory('Companies');
542 $im = DB_Dataobject::factory('Images');
543 $c->joinAdd($im, 'LEFT');
545 $c->selectAs($c, 'company_id_%s');
546 $c->selectAs($im, 'company_id_logo_id_%s');
547 $c->id = $this->company_id;
551 $aur = array_merge( $c->toArray(),$aur);
553 if (empty($c->company_id_logo_id_id)) {
555 $im = DB_Dataobject::factory('Images');
556 $im->ontable = 'Companies';
558 $im->imgtype = 'LOGO';
561 $im->selectAs($im, 'company_id_logo_id_%s');
562 if ($im->find(true)) {
564 foreach($im->toArray() as $k=>$v) {
571 $aur['perms'] = $this->getPerms();
572 $g = DB_DataObject::Factory('group_members');
573 $aur['groups'] = $g->listGroupMembership($this, 'name');
576 $aur['dailykey'] = '';
583 // ----------PERMS------ ----------------
586 //DB_DataObject::debugLevel(1);
587 // find out all the groups they are a member of.. + Default..
589 // ------ INIITIALIZE IF NO GROUPS ARE SET UP.
591 $g = DB_DataObject::Factory('group_rights');
597 return $g->adminRights(); // system is not set up - so they get full rights.
599 //DB_DataObject::debugLevel(1);
600 $g = DB_DataObject::Factory('group_members');
601 $g->whereAdd('group_id is NOT NULL AND user_id IS NOT NULL');
603 // add the current user to the admin group..
604 $g = DB_DataObject::Factory('Groups');
605 if ($g->get('name', 'Administrators')) {
606 $gm = DB_DataObject::Factory('group_members');
607 $gm->group_id = $g->id;
608 $gm->user_id = $this->id;
614 // ------ STANDARD PERMISSION HANDLING.
615 $isOwner = $this->company()->comptype == 'OWNER';
616 $g = DB_DataObject::Factory('group_members');
617 $grps = $g->listGroupMembership($this);
619 $isAdmin = $g->inAdmin;
620 //echo '<PRE>'; print_r($grps);var_dump($isAdmin);
621 // the load all the perms for those groups, and add them all together..
622 // then load all those
623 $g = DB_DataObject::Factory('group_rights');
624 $ret = $g->listPermsFromGroupIds($grps, $isAdmin, $isOwner);
625 //echo '<PRE>';print_r($ret);
631 *Basic group fetching - probably needs to filter by type eventually.
633 *@param String $what - fetchall() argument - eg. 'name' returns names of all groups that they are members of.
636 function groups($what=false)
638 $g = DB_DataObject::Factory('group_members');
639 $grps = $g->listGroupMembership($this);
640 $g = DB_DataObject::Factory('Groups');
641 $g->whereAddIn('id', $grps, 'int');
642 return $g->fetchAll($what);
648 function hasPerm($name, $lvl)
650 static $pcache = array();
652 if (!isset($pcache[$this->id])) {
653 $pcache[$this->id] = $this->getPerms();
655 // echo "<PRE>";print_r($pcache[$au->id]);
656 // var_dump($pcache[$au->id]);
657 if (empty($pcache[$this->id][$name])) {
661 return strpos($pcache[$this->id][$name], $lvl) > -1;
665 // ------------ROO HOOKS------------------------------------
666 function applyFilters($q, $au, $roo)
668 //DB_DataObject::DebugLevel(1);
669 if (!empty($q['query']['person_not_internal'])) {
670 $this->whereAdd(" join_company_id_id.isOwner = 0 ");
673 if (!empty($q['query']['person_internal_only_all'])) {
676 // must be internal and not current user (need for distribution list)
677 // user has a projectdirectory entry and role is not blank.
678 //DB_DataObject::DebugLevel(1);
679 $pd = DB_DataObject::factory('ProjectDirectory');
680 $pd->whereAdd("role != ''");
682 $pd->selectAdd('distinct(person_id) as person_id');
683 $roled = $pd->fetchAll('person_id');
685 {$this->tableName()}.id IN (".implode(',', $roled) . ")
687 $this->whereAdd(" join_company_id_id.comptype = 'OWNER' $rs ");
690 // -- for distribution
691 if (!empty($q['query']['person_internal_only'])) {
692 // must be internal and not current user (need for distribution list)
693 $this->whereAdd(" join_company_id_id.comptype = 'OWNER'");
695 //$this->whereAdd(($this->tableName() == 'Person' ? 'Person' : "join_person_id_id") .
696 // ".id != ".$au->id);
697 $this->whereAdd("Person.id != {$au->id}");
700 if (!empty($q['query']['comptype_or_company_id'])) {
701 // DB_DataObject::debugLevel(1);
702 $bits = explode(',', $q['query']['comptype_or_company_id']);
703 $id = (int) array_pop($bits);
704 $ct = $this->escape($bits[0]);
706 $this->whereAdd(" join_company_id_id.comptype = '$ct' OR Person.company_id = $id");
712 if (!empty($q['query']['person_inactive'])) {
713 // DB_Dataobject::debugLevel(1);
716 $tn_p = $this->tableName();
717 $tn_gm = DB_DataObject::Factory('group_members')->tableName();
718 $tn_g = DB_DataObject::Factory('Groups')->tableName();
720 ///---------------- Group views --------
721 if (!empty($q['query']['in_group'])) {
722 // DB_DataObject::debugLevel(1);
723 $ing = (int) $q['query']['in_group'];
724 if ($q['query']['in_group'] == -1) {
726 // list all staff who are not in a group.
727 $this->whereAdd("Person.id NOT IN (
728 SELECT distinct(user_id) FROM $tn_gm LEFT JOIN
729 $tn_g ON $tn_g.id = $tn_gm.group_id
730 WHERE $tn_g.type = ".$q['query']['type']."
736 $this->whereAdd("$tn_p.id IN (
737 SELECT distinct(user_id) FROM $tn_gm
738 WHERE group_id = $ing
744 // #2307 Search Country!!
745 if (!empty($q['query']['in_country'])) {
746 // DB_DataObject::debugLevel(1);
747 $inc = $q['query']['in_country'];
748 $this->whereAdd("$tn_p.countries LIKE '%{$inc}%'");
751 if (!empty($q['query']['not_in_directory'])) {
752 // it's a Person list..
753 // DB_DATaobjecT::debugLevel(1);
755 // specific to project directory which is single comp. login
757 $owncomp = DB_DataObject::Factory('Companies');
758 $owncomp->get('comptype', 'OWNER');
759 if ($q['company_id'] == $owncomp->id) {
765 if ( $q['query']['not_in_directory'] > -1) {
766 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
767 // can list current - so that it does not break!!!
768 $this->whereAdd("$tn_p.id NOT IN
769 ( SELECT distinct person_id FROM $tn_pd WHERE
770 project_id = " . $q['query']['not_in_directory'] . " AND
771 company_id = " . $this->company_id . ')');
775 if (!empty($q['query']['role'])) {
776 // it's a Person list..
777 // DB_DATaobjecT::debugLevel(1);
779 // specific to project directory which is single comp. login
781 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
782 // can list current - so that it does not break!!!
783 $this->whereAdd("$tn_p.id IN
784 ( SELECT distinct person_id FROM $tn_pd WHERE
785 role = '". $this->escape($q['query']['role']) ."'
791 if (!empty($q['query']['project_member_of'])) {
792 // this is also a flag to return if they are a member..
793 //DB_DataObject::debugLevel(1);
794 $do = DB_DataObject::factory('ProjectDirectory');
795 $do->project_id = $q['query']['project_member_of'];
796 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
797 $this->joinAdd($do,array('joinType' => 'LEFT', 'useWhereAsOn' => true));
798 $this->selectAdd("IF($tn_pd.id IS NULL, 0, $tn_pd.id ) as is_member");
801 if (!empty($q['query']['project_member_filter'])) {
802 $this->having('is_member !=0');
808 if(!empty($q['query']['name'])){
810 Person.name LIKE '%{$this->escape($q['query']['name'])}%'
814 if (!empty($q['query']['search'])) {
816 // use our magic search builder...
818 require_once 'Text/SearchParser.php';
819 $x = new Text_SearchParser($q['query']['search']);
827 "join_company_id_id.name"
830 $str = $x->toSQL(array(
833 'company' => 'join_company_id_id.name',
834 //'country' => 'Clipping.country',
835 // 'media' => 'Clipping.media_name',
837 'escape' => array($this->getDatabaseConnection(), 'escapeSimple'), /// pear db or mdb object..
842 $this->whereAdd($str); /*
843 $tn_p.name LIKE '%$s%' OR
844 $tn_p.email LIKE '%$s%' OR
845 $tn_p.role LIKE '%$s%' OR
846 $tn_p.phone LIKE '%$s%' OR
847 $tn_p.remarks LIKE '%$s%'
853 function setFromRoo($ar, $roo)
856 if (!empty($ar['passwd1'])) {
857 $this->setPassword($ar['passwd1']);
862 ($this->email == $roo->old->email)&&
863 ($this->company_id == $roo->old->company_id)
867 if (empty($this->email)) {
870 $xx = DB_Dataobject::factory('Person');
872 'email' => $this->email,
873 // 'company_id' => $x->company_id
877 return "Duplicate Email found";
883 * before Delete - delete significant dependancies..
884 * this is called after checkPerm..
887 function beforeDelete()
890 $e = DB_DataObject::Factory('Events');
891 $e->whereAdd('person_id = ' . $this->id);
900 * Check if the a user has access to modify this item.
901 * @param String $lvl Level (eg. Core.Projects)
902 * @param Pman_Core_DataObjects_Person $au The authenticated user.
903 * @param boolean $changes alllow changes???
905 * @return false if no access..
907 function checkPerm($lvl, $au, $changes=false) //heck who is trying to access this. false == access denied..
910 // do we have an empty system..
911 if ($au && $au->id == -1) {
915 // determine if it's staff!!!
917 if ($au->company()->comptype != 'OWNER') {
919 // - can not change company!!!
921 isset($changes['company_id']) &&
922 $changes['company_id'] != $au->company_id) {
925 // can only set new emails..
927 !empty($this->email) &&
928 isset($changes['email']) &&
929 $changes['email'] != $this->email) {
933 // edit self... - what about other staff members...
935 return $this->company_id == $au->company_id;
939 // yes, only owner company can mess with this...
940 $owncomp = DB_DataObject::Factory('Companies');
941 $owncomp->get('comptype', 'OWNER');
943 $isStaff = ($this->company_id == $owncomp->id);
947 // extra case change passwod?
948 case 'P': //??? password
949 // standard perms -- for editing + if the user is dowing them selves..
950 $ret = $isStaff ? $au->hasPerm("Core.Staff", "E") : $au->hasPerm("Core.Person", "E");
951 return $ret || $au->id == $this->id;
954 return $isStaff ? $au->hasPerm("Core.Staff", $lvl) : $au->hasPerm("Core.Person", $lvl);
960 function onInsert($req, $roo)
963 $p = DB_DataObject::factory('person');
964 if ($roo->authUser->id < 0 && $p->count() == 1) {
965 // this seems a bit risky...
967 $g = DB_DataObject::factory('Groups');
971 $g->get('name', 'Administrators');
973 $p = DB_DataObject::factory('group_members');
974 $p->group_id = $g->id;
975 $p->user_id = $this->id;
978 $roo->addEvent("ADD", $p, $g->toEventString(). " Added " . $this->toEventString());
982 if (!empty($req['project_id_addto'])) {
983 $pd = DB_DataObject::factory('ProjectDirectory');
984 $pd->project_id = $req['project_id_addto'];
985 $pd->person_id = $this->id;
987 $pd->office_id = $this->office_id;
988 $pd->company_id = $this->company_id;
994 function importFromArray($roo, $persons, $opts)
996 if (empty($opts['prefix'])) {
997 $roo->jerr("opts[prefix] is empty - you can not just create passwords based on the user names");
1000 if (!is_array($persons) || empty($persons)) {
1001 $roo->jerr("error in the person data. - empty on not valid");
1003 DB_DataObject::factory('groups')->initGroups();
1005 foreach($persons as $person){
1006 $p = DB_DataObject::factory('person');
1007 if($p->get('name', $person['name'])){
1010 $p->setFrom($person);
1012 $companies = DB_DataObject::factory('companies');
1013 if(!$companies->get('comptype', 'OWNER')){
1014 $roo->jerr("Missing OWNER companies!");
1016 $p->company_id = $companies->pid();
1017 // strip the 'spaces etc.. make lowercase..
1018 $name = strtolower(str_replace(' ', '', $person['name']));
1019 $p->setPassword("{$opts['prefix']}{$name}");
1022 // if $person->groups is set.. then
1023 // add this person to that group eg. groups : [ 'Administrator' ]
1024 if(!empty($person['groups'])){
1025 $groups = DB_DataObject::factory('groups');
1026 if(!$groups->get('name', $person['groups'])){
1027 $roo->jerr("Missing groups : {$person['groups']}");
1029 $gm = DB_DataObject::factory('group_members');
1030 $gm->change($p, $groups, true);
1033 $p->onInsert(array(), $roo);
1037 function getEmailName()
1041 if(!empty($this->honor)){
1042 array_push($name, $this->honor);
1045 if(!empty($this->name)){
1046 array_push($name, $this->name);
1048 return implode(' ', $name);
1051 if(!empty($this->firstname) || !empty($this->lastname)){
1052 array_push($name, $this->firstname);
1053 array_push($name, $this->lastname);
1055 $name = array_filter($name);
1060 return $this->email;