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 $_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');
287 $member->group_id = $group->id;
288 if($member->find(true)){
289 $default_admin = DB_DataObject::factory('Person');
290 if(!$default_admin->get($member->user_id)){
291 $default_admin = false;
296 $u = DB_DataObject::factory('Person');
297 $ff = HTML_FlexyFramework::get();
298 if (!empty($ff->Pman['local_autoauth']) &&
299 (!empty($_SERVER['SERVER_ADDR'])) &&
300 ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
301 ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') &&
302 ($default_admin || $u->get('email', $ff->Pman['local_autoauth']))
304 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($default_admin ? $default_admin : $u);
309 $u = DB_DataObject::factory('Person');
311 if (!empty($_SERVER['PHP_AUTH_USER'])
313 !empty($_SERVER['PHP_AUTH_PW'])
315 $u->get('email', $_SERVER['PHP_AUTH_USER'])
317 $u->checkPassword($_SERVER['PHP_AUTH_PW'])
319 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($u);
323 if (!empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
327 // not in session or not matched...
328 $u = DB_DataObject::factory('Person');
329 $u->whereAdd(' LENGTH(passwd) > 0');
331 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $n;
332 $error = PEAR::getStaticProperty('DB_DataObject','lastError');
334 die($error->toString()); // not really a good thing to do...
336 if (!$n){ // authenticated as there are no users in the system...
343 function getAuthUser()
345 if (!$this->isAuth()) {
348 $db = $this->getDatabaseConnection();
350 $ff= HTML_FlexyFramework::get();
351 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
355 if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
356 $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
358 $u = DB_DataObject::factory('Person');
359 if ($u->get($a->id)) { /// && strlen($u->passwd)) {
365 if (empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
366 $u = DB_DataObject::factory('Person');
367 $u->whereAdd(' LENGTH(passwd) > 0');
368 $_SESSION[__CLASS__][$sesPrefix .'-empty'] = $u->count();
372 if (empty( $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
374 // fake person - open system..
375 //$ce = DB_DataObject::factory('core_enum');
379 $u = DB_DataObject::factory('Person');
382 // if a company has been created fill that in in company_id_id
383 $c = DB_DAtaObject::factory('Companies')->lookupOwner();
385 $u->company_id_id = $c->pid();
386 $u->company_id= $c->pid();
396 $this->isAuth(); // force session start..
397 if (!$this->verifyAuth()) {
400 $db = $this->getDatabaseConnection();
403 // open up iptables at login..
404 $dbname = $this->database();
405 touch( '/tmp/run_pman_admin_iptables-'.$dbname);
407 // refresh admin group if we are logged in as one..
408 //DB_DataObject::debugLevel(1);
409 $g = DB_DataObject::factory('Groups');
411 $g->get('name', 'Administrators');
412 $gm = DB_DataObject::Factory('group_members');
413 if (in_array($g->id,$gm->listGroupMembership($this))) {
414 // refresh admin groups.
415 $gr = DB_DataObject::Factory('group_rights');
416 $gr->applyDefs($g, 0);
418 $ff= HTML_FlexyFramework::get();
419 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
422 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($this);
427 $this->isAuth(); // force session start..
428 $db = $this->getDatabaseConnection();
429 $ff= HTML_FlexyFramework::get();
430 $sesPrefix = $ff->appNameShort .'-' .get_class($this) .'-'.$db->dsn['database'] ;
432 $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
435 function genPassKey ($t)
437 return md5($this->email . $t. $this->passwd);
439 function simpleAuthKey($m = 0)
441 $month = $m > -1 ? date('Y-m') : date('Y-m', strtotime('LAST MONTH'));
443 return md5(implode(',' , array($month, $this->email , $this->passwd, $this->id)));
445 function checkPassword($val)
448 if (substr($this->passwd,0,1) == '$') {
449 return crypt($val,$this->passwd) == $this->passwd ;
451 // old style md5 passwords...- cant be used with courier....
452 return md5($val) == $this->passwd;
454 function setPassword($value)
457 while(strlen($salt)<9) {
458 $salt.=chr(rand(64,126));
459 //php -r var_dump(crypt('testpassword', '$1$'. (rand(64,126)). '$'));
461 $this->passwd = crypt($value, '$1$'. $salt. '$');
466 function generatePassword() // genearte a password (add set 'rawPasswd' to it's value)
468 require_once 'Text/Password.php';
469 $this->rawPasswd = strtr(ucfirst(Text_Password::create(5)).ucfirst(Text_Password::create(5)), array(
470 "a"=>"4", "e"=>"3", "i"=>"1", "o"=>"0", "s"=>"5", "t"=>"7"));
471 $this->setPassword($this->rawPasswd);
472 return $this->rawPasswd;
477 $x = DB_DataObject::factory('Companies');
479 $x->get($this->company_id);
482 function loadCompany()
484 $this->company = $this->company();
489 return $this->active;
491 function authUserName($n) // set username prior to acheck user exists query.
494 $this->whereAdd('LENGTH(passwd) > 1');
499 if (!func_num_args()) {
502 $val = array_shift(func_get_args());
503 if ($val == $this->lang) {
513 function authUserArray()
516 $aur = $this->toArray();
523 //DB_DataObject::debugLevel(1);
524 $c = DB_Dataobject::factory('Companies');
525 $im = DB_Dataobject::factory('Images');
526 $c->joinAdd($im, 'LEFT');
528 $c->selectAs($c, 'company_id_%s');
529 $c->selectAs($im, 'company_id_logo_id_%s');
530 $c->id = $this->company_id;
534 $aur = array_merge( $c->toArray(),$aur);
536 if (empty($c->company_id_logo_id_id)) {
538 $im = DB_Dataobject::factory('Images');
539 $im->ontable = 'Companies';
541 $im->imgtype = 'LOGO';
544 $im->selectAs($im, 'company_id_logo_id_%s');
545 if ($im->find(true)) {
547 foreach($im->toArray() as $k=>$v) {
554 $aur['perms'] = $this->getPerms();
555 $g = DB_DataObject::Factory('group_members');
556 $aur['groups'] = $g->listGroupMembership($this, 'name');
559 $aur['dailykey'] = '';
566 // ----------PERMS------ ----------------
569 //DB_DataObject::debugLevel(1);
570 // find out all the groups they are a member of.. + Default..
572 // ------ INIITIALIZE IF NO GROUPS ARE SET UP.
574 $g = DB_DataObject::Factory('group_rights');
580 return $g->adminRights(); // system is not set up - so they get full rights.
582 //DB_DataObject::debugLevel(1);
583 $g = DB_DataObject::Factory('group_members');
584 $g->whereAdd('group_id is NOT NULL AND user_id IS NOT NULL');
586 // add the current user to the admin group..
587 $g = DB_DataObject::Factory('Groups');
588 if ($g->get('name', 'Administrators')) {
589 $gm = DB_DataObject::Factory('group_members');
590 $gm->group_id = $g->id;
591 $gm->user_id = $this->id;
597 // ------ STANDARD PERMISSION HANDLING.
598 $isOwner = $this->company()->comptype == 'OWNER';
599 $g = DB_DataObject::Factory('group_members');
600 $grps = $g->listGroupMembership($this);
602 $isAdmin = $g->inAdmin;
603 //echo '<PRE>'; print_r($grps);var_dump($isAdmin);
604 // the load all the perms for those groups, and add them all together..
605 // then load all those
606 $g = DB_DataObject::Factory('group_rights');
607 $ret = $g->listPermsFromGroupIds($grps, $isAdmin, $isOwner);
608 //echo '<PRE>';print_r($ret);
614 *Basic group fetching - probably needs to filter by type eventually.
616 *@param String $what - fetchall() argument - eg. 'name' returns names of all groups that they are members of.
619 function groups($what=false)
621 $g = DB_DataObject::Factory('group_members');
622 $grps = $g->listGroupMembership($this);
623 $g = DB_DataObject::Factory('Groups');
624 $g->whereAddIn('id', $grps, 'int');
625 return $g->fetchAll($what);
631 function hasPerm($name, $lvl)
633 static $pcache = array();
635 if (!isset($pcache[$this->id])) {
636 $pcache[$this->id] = $this->getPerms();
638 // echo "<PRE>";print_r($pcache[$au->id]);
639 // var_dump($pcache[$au->id]);
640 if (empty($pcache[$this->id][$name])) {
644 return strpos($pcache[$this->id][$name], $lvl) > -1;
648 // ------------ROO HOOKS------------------------------------
649 function applyFilters($q, $au, $roo)
651 //DB_DataObject::DebugLevel(1);
652 if (!empty($q['query']['person_not_internal'])) {
653 $this->whereAdd(" join_company_id_id.isOwner = 0 ");
657 if (!empty($q['query']['person_internal_only_all'])) {
660 // must be internal and not current user (need for distribution list)
661 // user has a projectdirectory entry and role is not blank.
662 //DB_DataObject::DebugLevel(1);
663 $pd = DB_DataObject::factory('ProjectDirectory');
664 $pd->whereAdd("role != ''");
666 $pd->selectAdd('distinct(person_id) as person_id');
667 $roled = $pd->fetchAll('person_id');
669 {$this->tableName()}.id IN (".implode(',', $roled) . ")
671 $this->whereAdd(" join_company_id_id.comptype = 'OWNER' $rs ");
674 // -- for distribution
675 if (!empty($q['query']['person_internal_only'])) {
676 // must be internal and not current user (need for distribution list)
677 $this->whereAdd(" join_company_id_id.comptype = 'OWNER'");
679 //$this->whereAdd(($this->tableName() == 'Person' ? 'Person' : "join_person_id_id") .
680 // ".id != ".$au->id);
681 $this->whereAdd("Person.id != {$au->id}");
684 if (!empty($q['query']['comptype_or_company_id'])) {
685 // DB_DataObject::debugLevel(1);
686 $bits = explode(',', $q['query']['comptype_or_company_id']);
687 $id = (int) array_pop($bits);
688 $ct = $this->escape($bits[0]);
690 $this->whereAdd(" join_company_id_id.comptype = '$ct' OR Person.company_id = $id");
696 if (!empty($q['query']['person_inactive'])) {
697 // DB_Dataobject::debugLevel(1);
700 $tn_p = $this->tableName();
701 $tn_gm = DB_DataObject::Factory('group_members')->tableName();
702 $tn_g = DB_DataObject::Factory('Groups')->tableName();
704 ///---------------- Group views --------
705 if (!empty($q['query']['in_group'])) {
706 // DB_DataObject::debugLevel(1);
707 $ing = (int) $q['query']['in_group'];
708 if ($q['query']['in_group'] == -1) {
710 // list all staff who are not in a group.
711 $this->whereAdd("Person.id NOT IN (
712 SELECT distinct(user_id) FROM $tn_gm LEFT JOIN
713 $tn_g ON $tn_g.id = $tn_gm.group_id
714 WHERE $tn_g.type = ".$q['query']['type']."
720 $this->whereAdd("$tn_p.id IN (
721 SELECT distinct(user_id) FROM $tn_gm
722 WHERE group_id = $ing
728 if (!empty($q['query']['not_in_directory'])) {
729 // it's a Person list..
730 // DB_DATaobjecT::debugLevel(1);
732 // specific to project directory which is single comp. login
734 $owncomp = DB_DataObject::Factory('Companies');
735 $owncomp->get('comptype', 'OWNER');
736 if ($q['company_id'] == $owncomp->id) {
742 if ( $q['query']['not_in_directory'] > -1) {
743 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
744 // can list current - so that it does not break!!!
745 $this->whereAdd("$tn_p.id NOT IN
746 ( SELECT distinct person_id FROM $tn_pd WHERE
747 project_id = " . $q['query']['not_in_directory'] . " AND
748 company_id = " . $this->company_id . ')');
752 if (!empty($q['query']['role'])) {
753 // it's a Person list..
754 // DB_DATaobjecT::debugLevel(1);
756 // specific to project directory which is single comp. login
758 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
759 // can list current - so that it does not break!!!
760 $this->whereAdd("$tn_p.id IN
761 ( SELECT distinct person_id FROM $tn_pd WHERE
762 role = '". $this->escape($q['query']['role']) ."'
768 if (!empty($q['query']['project_member_of'])) {
769 // this is also a flag to return if they are a member..
770 //DB_DataObject::debugLevel(1);
771 $do = DB_DataObject::factory('ProjectDirectory');
772 $do->project_id = $q['query']['project_member_of'];
773 $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
774 $this->joinAdd($do,array('joinType' => 'LEFT', 'useWhereAsOn' => true));
775 $this->selectAdd("IF($tn_pd.id IS NULL, 0, $tn_pd.id ) as is_member");
778 if (!empty($q['query']['project_member_filter'])) {
779 $this->having('is_member !=0');
785 if (!empty($q['query']['search'])) {
787 // use our magic search builder...
789 require_once 'Text/SearchParser.php';
790 $x = new Text_SearchParser($q['query']['search']);
798 "join_company_id_id.name"
801 $str = $x->toSQL(array(
804 'company' => 'join_company_id_id.name',
805 //'country' => 'Clipping.country',
806 // 'media' => 'Clipping.media_name',
808 'escape' => array($this->getDatabaseConnection(), 'escapeSimple'), /// pear db or mdb object..
813 $this->whereAdd($str); /*
814 $tn_p.name LIKE '%$s%' OR
815 $tn_p.email LIKE '%$s%' OR
816 $tn_p.role LIKE '%$s%' OR
817 $tn_p.phone LIKE '%$s%' OR
818 $tn_p.remarks LIKE '%$s%'
825 function setFromRoo($ar, $roo)
828 if (!empty($ar['passwd1'])) {
829 $this->setPassword($ar['passwd1']);
834 ($this->email == $roo->old->email)&&
835 ($this->company_id == $roo->old->company_id)
839 if (empty($this->email)) {
842 $xx = DB_Dataobject::factory('Person');
844 'email' => $this->email,
845 // 'company_id' => $x->company_id
849 return "Duplicate Email found";
855 * before Delete - delete significant dependancies..
856 * this is called after checkPerm..
859 function beforeDelete()
862 $e = DB_DataObject::Factory('Events');
863 $e->whereAdd('person_id = ' . $this->id);
872 * Check if the a user has access to modify this item.
873 * @param String $lvl Level (eg. Core.Projects)
874 * @param Pman_Core_DataObjects_Person $au The authenticated user.
875 * @param boolean $changes alllow changes???
877 * @return false if no access..
879 function checkPerm($lvl, $au, $changes=false) //heck who is trying to access this. false == access denied..
882 // do we have an empty system..
883 if ($au && $au->id == -1) {
887 // determine if it's staff!!!
889 if ($au->company()->comptype != 'OWNER') {
891 // - can not change company!!!
893 isset($changes['company_id']) &&
894 $changes['company_id'] != $au->company_id) {
897 // can only set new emails..
899 !empty($this->email) &&
900 isset($changes['email']) &&
901 $changes['email'] != $this->email) {
905 // edit self... - what about other staff members...
907 return $this->company_id == $au->company_id;
911 // yes, only owner company can mess with this...
912 $owncomp = DB_DataObject::Factory('Companies');
913 $owncomp->get('comptype', 'OWNER');
915 $isStaff = ($this->company_id == $owncomp->id);
919 // extra case change passwod?
920 case 'P': //??? password
921 // standard perms -- for editing + if the user is dowing them selves..
922 $ret = $isStaff ? $au->hasPerm("Core.Staff", "E") : $au->hasPerm("Core.Person", "E");
923 return $ret || $au->id == $this->id;
926 return $isStaff ? $au->hasPerm("Core.Staff", $lvl) : $au->hasPerm("Core.Person", $lvl);
931 function onInsert($req, $roo)
934 $p = DB_DataObject::factory('person');
935 if ($roo->authUser->id < 0 && $p->count() == 1) {
936 // this seems a bit risky...
938 $g = DB_DataObject::factory('Groups');
942 $g->get('name', 'Administrators');
944 $p = DB_DataObject::factory('group_members');
945 $p->group_id = $g->id;
946 $p->user_id = $this->id;
949 $roo->addEvent("ADD", $p, $g->toEventString(). " Added " . $this->toEventString());
953 if (!empty($req['project_id_addto'])) {
954 $pd = DB_DataObject::factory('ProjectDirectory');
955 $pd->project_id = $req['project_id_addto'];
956 $pd->person_id = $this->id;
958 $pd->office_id = $this->office_id;
959 $pd->company_id = $this->company_id;
965 function importFromArray($roo, $persons, $opts)
967 if (empty($opts['prefix'])) {
968 $roo->jerr("opts[prefix] is empty - you can not just create passwords based on the user names");
971 if (!is_array($persons) || empty($persons)) {
972 $roo->jerr("error in the person data. - empty on not valid");
974 DB_DataObject::factory('groups')->initGroups();
976 foreach($persons as $person){
977 $p = DB_DataObject::factory('person');
978 if($p->get('name', $person['name'])){
981 $p->setFrom($person);
983 $companies = DB_DataObject::factory('companies');
984 if(!$companies->get('comptype', 'OWNER')){
985 $roo->jerr("Missing OWNER companies!");
987 $p->company_id = $companies->pid();
988 // strip the 'spaces etc.. make lowercase..
989 $name = strtolower(str_replace(' ', '', $person['name']));
990 $p->setPassword("{$opts['prefix']}{$name}");
993 // if $person->groups is set.. then
994 // add this person to that group eg. groups : [ 'Administrator' ]
995 if(!empty($person['groups'])){
996 $groups = DB_DataObject::factory('groups');
997 if(!$groups->get('name', $person['groups'])){
998 $roo->jerr("Missing groups : {$person['groups']}");
1000 $gm = DB_DataObject::factory('group_members');
1001 $gm->change($p, $groups, true);
1004 $p->onInsert(array(), $roo);