0) { $sql = "select login,auth_src_id from epi_users where user_id=$user_id"; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $login = stripslashes(htmlentities($row["login"])); $x_auth_src_id = $row["auth_src_id"]; }//end of while loop through row $db->free_result_set($result); }//end of if result } $auth_servers[0] = "Epiware"; $sql = "select auth_src_id,title from auth_sources"; if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $auth_servers[$row["auth_src_id"]] = $row["title"]; }//end of while loop through row $db->free_result_set($result); }//end of if result function check_install(){ if(is_new_installation()) { echo ""; echo "This is a new installation. There are no users registered with the system. Set the email in the file " . EPI_CONFIG_FILE . ", and use the email that is set by the variable SUPER_USER to login into the system.

PUT YOUR EMAIL IN FILE " . EPI_CONFIG_FILE . " AND THEN LOGIN

"; echo "
"; return 1; } else { return 0; } } // END OF check_install ?>user_id = 0; $this->l_name = ""; $this->f_name = ""; $this->phone = ""; $this->phone_ext = ""; $this->fax = ""; $this->email = ""; $this->password = ""; $this->status = 0; $this->reminder = 0; $this->secret_word = ""; $this->company = ""; $this->discipline = ""; $this->street1 = ""; $this->street2 = ""; $this->city = ""; $this->state = ""; $this->country = ""; $this->zip = ""; $this->home_street1 = ""; $this->home_street2 = ""; $this->home_city = ""; $this->home_state = ""; $this->home_zip = ""; $this->last_visit = mktime(); $this->pager = ""; $this->pager_ext = ""; $this->cellular = ""; $this->red = ""; $this->icom = ""; $this->pager_email = ""; $this->point_of_contact = ""; $this->position = ""; $this->external_id = ""; $this->has_pa = 0; $this->date_registered = mktime(); $this->login = ""; $this->phone_dsn = ""; $this->email_alternate = ""; $this->user_access_level = 0; $this->picture = ""; $this->rank = ""; $this->title = ""; $this->classification = 0; $this->timezone_gmt_offset = 0; $this->timezone_gmt = ""; $this->observe_dst = 0; $this->default_group_id = 0; $this->default_set_by_user = 0; $this->sid = ""; }//end of epi_users function check_login($new_login,$auth_src,&$db,$mq=false) { $num = 0; // Check to see if LOGIN already takenn... even if OLD desativedd.... // DO NOT USE SAME LOGIN Again.... $sql = "select count(*) as num from users where login=".$db->qstr($new_login,$mq) ; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $num = $row["num"]; }//end of while loop through row $db->free_result_set($result); }//end of if result if($num==0) { return (true); } else { return (false); } }//end of function to check a login name function make_password() { $len = 8; mt_srand((double)microtime() * 1000000); $pwd = ''; for($i = 0; $i < $len ; $i++) { $num = mt_rand(48, 122); if (($num > 96 && $num < 123 ) || ($num > 64 && $num < 91) || ($num > 47 && $num < 58)) { $pwd .= chr($num); } else { $i--; } }//end of for loop return $pwd; }//end of function make_password function get($user_id,&$db) { /*$sql= "select user_id,l_name,f_name,phone,phone_ext,fax,email,password,"; $sql .= "status,reminder,company, street1,street2,city,state,country,zip,"; $sql .= "home_street1,home_street2,home_city,home_state,home_zip,last_visit,"; $sql .= "pager,pager_ext,cellular,red,icom,pager_email,point_of_contact,position, "; $sql .= "external_id,login,email_alternate,user_access_level,picture, "; $sql .= " rank,classification,default_group_id, default_set_by_user "; $sql.= "from users a "; $sql.= "where a.user_id=$user_id ";*/ $sql = "select * "; $sql.= "from users where user_id='".$user_id."'"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { while(list($k,$v)=each($row)) { $this->{$k} = $v; } $this->last_visit = $db->date_handler->db2system($this->last_visit); }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get // Added new functionf or get all users for a master user list. -rg function get_all(&$db,$letter="") { $sql= "SELECT user_id,l_name,f_name,phone,phone_ext,fax,email,password,"; $sql .= "status,reminder,company, street1,street2,city,state,country,zip,"; $sql .= "home_street1,home_street2,home_city,home_state,home_zip,last_visit,"; $sql .= "pager,pager_ext,cellular,red,icom,pager_email,point_of_contact,position, "; $sql .= "external_id,login,email_alternate,user_access_level,picture,rank,classification "; $sql.= "FROM users"; if($letter!="") $sql.= " WHERE l_name LIKE '".$letter."%'"; $sql.= " ORDER BY l_name"; if($result = $db->perform_looping_query($sql)) return($result); else return false; }//end of function get function get_all_active(&$db) { $sql= "SELECT user_id,l_name,f_name,email,company,classification "; $sql.= "FROM users "; $sql.= "where status > -1 "; $sql.= "order by l_name"; return($result = $db->perform_looping_query($sql)); }//end of function get function get_by_email(&$db) { $sql= "select user_id,l_name,f_name,phone,phone_ext,fax,email,password,"; $sql .= "status,reminder,company, street1,street2,city,state,country,zip,"; $sql .= "home_street1,home_street2,home_city,home_state,home_zip,last_visit,"; $sql .= "pager,pager_ext,cellular,red,icom,pager_email,point_of_contact,position, "; $sql .= "external_id,login,email_alternate,user_access_level,picture,rank,classification "; $sql.= "from users a "; $sql.= "where a.email=".$db->qstr($this->email,true); $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->user_id = $row["user_id"]; $this->login = $row["login"]; $this->password = $row["password"]; $this->status = $row["status"]; $this->f_name = $row["f_name"]; $this->l_name = $row["l_name"]; $this->l_name = $row["l_name"]; $this->user_access_level = $row["user_access_level"]; $this->email = $row["email"]; $this->rank = $row["rank"]; $this->company = $row["company"]; $this->phone_dsn = $row["phone_dsn"]; $this->email_alternate= $row["email_alternate"]; $this->cellular= $row["cellular"]; $this->phone= $row["phone"]; $this->phone_ext= $row["phone_ext"]; $this->street1= $row["street1"]; $this->street2= $row["street2"]; $this->city= $row["city"]; $this->state= $row["state"]; $this->zip= $row["zip"]; $this->home_street1= $row["home_street1"]; $this->home_street2= $row["home_street2"]; $this->home_city= $row["home_city"]; $this->home_state= $row["home_state"]; $this->home_zip= $row["home_zip"]; $this->cellular= $row["cellular"]; $this->pager= $row["pager"]; $this->pager_ext = $row["pager_ext"]; $this->pager_email= $row["pager_email"]; $this->position= $row["position"]; $this->fax= $row["fax"]; $this->icom= $row["icom"]; $this->point_of_contact= $row["point_of_contact"]; $this->classification= $row["classification"]; $this->picture= $row["picture"]; $this->external_id=$row["external_id"]; $this->last_visit = $db->date_handler->db2system($row["last_visit"]); }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get_by_email function insert($key,&$db,$mq=false,$override_id=false) { //increment table used if(!$override_id) { $next_id = $db->get_next_id("users"); $this->user_id = $next_id; } if($this->user_id > 0) { if($this->user_access_level==""){ $this->user_access_level=1; } if($this->date_registered==""){ $this->date_registered=date('Y-m-d'); } $this->save($db,$mq); //Join to a default group 1...... $epi_group_handler = new epi_group_handler(1,$db); $epi_group_handler->add_user_to_group(1,$this->user_id,$db); //This now a realm_id jk.. // THey can only belong to 1 of these realms where the key=400.. // This will classify the user... //$this->classification groups::make_user_govt_or_contractor($this->group_id, $this->user_id, $this->classification, $db); if($this->group_id!="" || $this->group_id!=1){ //Add to Group that is currently selected.. $epi_group_handler = new epi_group_handler($this->group_id,$db); $epi_group_handler->add_user_to_group($this->group_id,$this->user_id,$db); } return true; }//end of if a new key was returned else { return false; } }//end of function insert function save(&$db,$mq=false) { $sql= "replace into users ("; $sql.= "user_id,l_name,f_name,phone,phone_ext,fax,email,password,status,reminder,"; $sql.= "secret_word,company,discipline,street1,street2,city,state,country,zip,home_street1,home_street2,"; $sql.= "home_city,home_state,home_zip,last_visit,pager,pager_ext,cellular,red,icom,pager_email,point_of_contact,"; $sql.= "position,external_id,has_pa,date_registered,login,phone_dsn,email_alternate,user_access_level,picture,rank,"; $sql.= "title,classification,timezone_gmt_offset,timezone_gmt,observe_dst,default_group_id,default_set_by_user,sid) "; $sql.= "values ("; $sql.= ($this->user_id+0).","; $sql.= $db->qstr($this->l_name,$mq).","; $sql.= $db->qstr($this->f_name,$mq).","; $sql.= $db->qstr($this->phone,$mq).","; $sql.= $db->qstr($this->phone_ext,$mq).","; $sql.= $db->qstr($this->fax,$mq).","; $sql.= $db->qstr($this->email,$mq).","; $sql.= $db->qstr($this->password,$mq).","; $sql.= ($this->status+0).","; $sql.= ($this->reminder+0).","; $sql.= $db->qstr($this->secret_word,$mq).","; $sql.= $db->qstr($this->company,$mq).","; $sql.= $db->qstr($this->discipline,$mq).","; $sql.= $db->qstr($this->street1,$mq).","; $sql.= $db->qstr($this->street2,$mq).","; $sql.= $db->qstr($this->city,$mq).","; $sql.= $db->qstr($this->state,$mq).","; $sql.= $db->qstr($this->country,$mq).","; $sql.= $db->qstr($this->zip,$mq).","; $sql.= $db->qstr($this->home_street1,$mq).","; $sql.= $db->qstr($this->home_street2,$mq).","; $sql.= $db->qstr($this->home_city,$mq).","; $sql.= $db->qstr($this->home_state,$mq).","; $sql.= $db->qstr($this->home_zip,$mq).","; $sql.= $db->qstr($db->date_handler->system2db($this->last_visit),$mq).","; $sql.= $db->qstr($this->pager,$mq).","; $sql.= $db->qstr($this->pager_ext,$mq).","; $sql.= $db->qstr($this->cellular,$mq).","; $sql.= $db->qstr($this->red,$mq).","; $sql.= $db->qstr($this->icom,$mq).","; $sql.= $db->qstr($this->pager_email,$mq).","; $sql.= $db->qstr($this->point_of_contact,$mq).","; $sql.= $db->qstr($this->position,$mq).","; $sql.= $db->qstr($this->external_id,$mq).","; $sql.= ($this->has_pa+0).","; $sql.= $db->qstr($db->date_handler->system2db($this->date_registered),$mq).","; $sql.= $db->qstr($this->login,$mq).","; $sql.= $db->qstr($this->phone_dsn,$mq).","; $sql.= $db->qstr($this->email_alternate,$mq).","; $sql.= ($this->user_access_level+0).","; $sql.= $db->qstr($this->picture,$mq).","; $sql.= $db->qstr($this->rank,$mq).","; $sql.= $db->qstr($this->title,$mq).","; $sql.= ($this->classification+0).","; $sql.= ($this->timezone_gmt_offset+0).","; $sql.= $db->qstr($this->timezone_gmt,$mq).","; $sql.= ($this->observe_dst+0).","; $sql.= ($this->default_group_id+0).","; $sql.= ($this->default_set_by_user+0).","; $sql.= $db->qstr($this->sid,$mq).")"; $db->last_sql = $sql; $answer = $db->perform_action_query($sql); return ($answer); }//end of function save function get_default_group($db) { $default_group="default group not set "; //If it has been set by user display the name, other wise, if($this->default_set_by_user==1) { $sql="select group_name from groups where group_id=" . "'" . $this->default_group_id . "'" . " and status>0 "; //print $sql; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $default_group=$row['group_name']; } } } return $default_group; } // END OF FUNCTION GET_DEFAULT_GROUP function update_default_group_id($db,$user_id,$default_group_id,$default_set_by_user,$mq=false) { // OK.. need to query before we update... // If the group is already set byt the user.. ,$default_set_by_user==1 // Then we cannot reset the default_group_id when a user switches projects.. // If default_set_by_user==1 then we can update... // if default_set_by_user==0 then we can update.. $update_permission=0; if($default_set_by_user==1){ $update_permission=1; } else { // This means the user is not directly setting the new default.. // We need to find out, if he has previosly selected a default. // If not then set to the new default. $sql="select default_set_by_user from users where user_id=$user_id "; // Need to take care of case where group has been turned OFF. // If if status of groups == -1 unset the primary group. //------------------------------------------- if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $default_set_by_user=$row['default_set_by_user']; if($default_set_by_user==0){ $update_permission=1; } } } // end of if result if($default_set_by_user>0) { //If group is inactive... We need to reset default.. $sql="select status from groups where group_id=$default_set_by_user " ; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $status=$row['status']; if($status==0) { $default_group_id=0; $default_set_by_user=0; } } } // end of if result } // End of if default_set_by_user 0 ... } if($update_permission==1){ $sql = "update users set default_group_id=" . $default_group_id . " , default_set_by_user=" .$default_set_by_user. " "; $sql.= "where user_id=". $user_id.""; //print $sql; //exit; return ($db->perform_action_query($sql)); } }//end of update_last_visit function update_last_visit($db,$mq=false) { $sql = "update users set last_visit=".$db->qstr($db->date_handler->system2db($this->last_visit),$mq)." "; $sql.= "where user_id=".$this->user_id.""; return ($db->perform_action_query($sql)); }//end of update_last_visit function update(&$db,$mq=false) { //updating the users table $sql = "update users set "; $sql.= "login=".$db->qstr($this->login,$mq).","; $sql.= "password=".$db->qstr($this->password,$mq).","; $sql.= "status=".$this->status.","; if($this->user_access_level!="") { $sql.= "user_access_level=".$this->user_access_level.","; } $sql.= "f_name=".$db->qstr($this->f_name,$mq).","; $sql.= "l_name=".$db->qstr($this->l_name,$mq).","; $sql.= "external_id=".$db->qstr($this->external_id,$mq).","; // Prevents user from blanking out his classifcaiton on update.. // Swear this was fixed before if($this->classification!="") { $sql.= "classification=".$db->qstr($this->classification,$mq).","; } if($this->email != "") { $sql.= "email=".$db->qstr($this->email,$mq).","; } $sql.= "last_visit=".$db->qstr($db->date_handler->system2db($this->last_visit),$mq)." "; $sql.= "where user_id=".$this->user_id.""; $uresult = $db->perform_action_query($sql); if($this->classification!="") { groups::make_user_govt_or_contractor($this->group_id, $this->user_id, $this->classification, $db); //exit; } return $uresult; }//end of function update function update_general(&$db,$mq=false) { //updating the users table $sql = "update users set "; $sql.= "rank=".$db->qstr($this->rank,$mq).","; $sql.= "company=".$db->qstr($this->company,$mq).","; $sql.= "phone=".$db->qstr($this->phone,$mq).","; $sql.= "phone_dsn=".$db->qstr($this->phone_dsn,$mq).","; $sql.= "cellular=".$db->qstr($this->cellular,$mq).","; $sql.= "email_alternate=".$db->qstr($this->email_alternate,$mq) ; $sql.= " where user_id=".$this->user_id.""; $uresult = $db->perform_action_query($sql); return $uresult; }//end of function update function update_external_id($db,$mp=false) { $sql = "update users set "; $sql.= "external_id=".$db->qstr($this->external_id,$mq); $sql.= " where user_id=".$db->qstr($this->user_id); return($result=$db->perform_action_query($sql)); } /***************** BACKUP DO NOT DELETE ******************** function deactivate(&$db) { if($this->user_id > 0) { $this->status = -1; $sql= "update users set "; $sql.= "status=-1 where user_id=".$this->user_id; $db->perform_action_query($sql); } }//end of deactivate ***********************************************************/ function deactivate(&$db) { if($this->user_id > 0) { $this->get($this->user_id,$db); $this->status = -1; return($this->update($db)); } }//end of deactivate function reactivate(&$db) { if($this->user_id > 0) { $this->status = 1; $sql= "update users set "; $sql.= "status=1 where user_id=".$this->user_id; $db->perform_action_query($sql); } }//end of reactivate function delete_picture(&$db) { $sql = "update users set picture='' where user_id=".$this->user_id; return($db->perform_action_query($sql)); } function delete(&$db) { //this should be modified to be sure that we delete from all the necessary tables... //..actually.. should never delete a user... but may be necessary $sql= "delete from users "; $sql.= "where user_id=".$this->user_id.""; $db->perform_action_query($sql); return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_users //################################################################################################ class epi_addr_types { var $addr_type; function epi_addr_types() { $this->addr_type = ""; } function get($addr_type,&$db) { $sql= "select addr_type "; $sql.= "from epi_addr_types "; $sql.= "where addr_type=".$db->qstr($this->addr_type,$mq).""; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->addr_type = $row["addr_type"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_addr_types ("; $sql.= "addr_type) "; $sql.= "values ("; $sql.= $db->qstr($this->addr_type,$mq).")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_addr_types set "; $sql.= "addr_type=".$db->qstr($this->addr_type,$mq)." "; $sql.= "where addr_type=".$db->qstr($this->addr_type,$mq).""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_addr_types "; $sql.= "where addr_type=".$db->qstr($this->addr_type,$mq).""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_addr_types //################################################################################################ class epi_email_addr { var $email_id; var $addr_id; function epi_email_addr() { $this->email_id = 0; $this->addr_id = 0; } function get($email_id,$addr_id,&$db) { $sql= "select email_id,addr_id "; $sql.= "from epi_email_addr "; $sql.= "where email_id=$email_id and addr_id=$addr_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->email_id = $row["email_id"]; $this->addr_id = $row["addr_id"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_email_addr ("; $sql.= "email_id,addr_id) "; $sql.= "values ("; $sql.= $this->email_id.","; $sql.= $this->addr_id.")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_email_addr set "; $sql.= "email_id=".$this->email_id.","; $sql.= "addr_id=".$this->addr_id." "; $sql.= "where email_id=".$this->email_id." and addr_id=".$this->addr_id.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_email_addr "; $sql.= "where email_id=".$this->email_id." and addr_id=".$this->addr_id.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_email_addr //################################################################################################ class epi_email_types { var $email_type; var $title; function epi_email_types() { $this->email_type = 0; $this->title = ""; } function get($email_type,&$db) { $sql= "select email_type,title "; $sql.= "from epi_email_types "; $sql.= "where email_type=$email_type"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->email_type = $row["email_type"]; $this->title = $row["title"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_email_types ("; $sql.= "email_type,title) "; $sql.= "values ("; $sql.= $this->email_type.","; $sql.= $db->qstr($this->title,$mq).")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_email_types set "; $sql.= "email_type=".$this->email_type.","; $sql.= "title=".$db->qstr($this->title,$mq)." "; $sql.= "where email_type=".$this->email_type.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_email_types "; $sql.= "where email_type=".$this->email_type.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_email_types //################################################################################################ class epi_group_addr { var $group_id; var $user_id; var $addr_id; function epi_group_addr() { $this->group_id = 0; $this->user_id = 0; $this->addr_id = 0; } function get($group_id,$user_id,&$db) { $sql= "select group_id,user_id,addr_id "; $sql.= "from epi_group_addr "; $sql.= "where group_id=$group_id and user_id=$user_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->group_id = $row["group_id"]; $this->user_id = $row["user_id"]; $this->addr_id = $row["addr_id"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_group_addr ("; $sql.= "group_id,user_id,addr_id) "; $sql.= "values ("; $sql.= $this->group_id.","; $sql.= $this->user_id.","; $sql.= $this->addr_id.")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_group_addr set "; $sql.= "group_id=".$this->group_id.","; $sql.= "user_id=".$this->user_id.","; $sql.= "addr_id=".$this->addr_id." "; $sql.= "where group_id=".$this->group_id." and user_id=".$this->user_id.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_group_addr "; $sql.= "where group_id=".$this->group_id." and user_id=".$this->user_id.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_group_addr //################################################################################################ class epi_phone_addr { var $phone_id; var $addr_id; function epi_phone_addr() { $this->phone_id = 0; $this->addr_id = 0; } function get($phone_id,$addr_id,&$db) { $sql= "select phone_id,addr_id "; $sql.= "from epi_phone_addr "; $sql.= "where phone_id=$phone_id and addr_id=$addr_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->phone_id = $row["phone_id"]; $this->addr_id = $row["addr_id"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_phone_addr ("; $sql.= "phone_id,addr_id) "; $sql.= "values ("; $sql.= $this->phone_id.","; $sql.= $this->addr_id.")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_phone_addr set "; $sql.= "phone_id=".$this->phone_id.","; $sql.= "addr_id=".$this->addr_id." "; $sql.= "where phone_id=".$this->phone_id." and addr_id=".$this->addr_id.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_phone_addr "; $sql.= "where phone_id=".$this->phone_id." and addr_id=".$this->addr_id.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_phone_addr //################################################################################################ class epi_phone_types { var $phone_type; var $order_num; var $phone_type_id; function epi_phone_types() { $this->phone_type = ""; $this->order_num = 0; } function get($phone_type_id,&$db) { $this->phone_type_id = $phone_type_id; $sql= "select phone_type,order_num,phone_type_id "; $sql.= "from epi_phone_types "; $sql.= "where phone_type_id=".$db->qstr($this->phone_type_id,$mq).""; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->phone_type = $row["phone_type"]; $this->order_num = $row["order_num"]; $this->phone_type_id = $row["phone_type_id"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { $sql= "insert into epi_phone_types ("; $sql.= "phone_type,order_num,phone_type_id) "; $sql.= "values ("; $sql.= $db->qstr($this->phone_type,$mq).",".$this->order_num.",".$this->phone_type_id.")"; return ($db->perform_action_query($sql)); }//end of function insert function update(&$db,$mq=false) { $sql= "update epi_phone_types set "; $sql.= "phone_type=".$db->qstr($this->phone_type,$mq).", "; $sql.= "order_num=".$this->order_num.","; $sql.= "phone_type_id=".$db->qstr($this->phone_type_id,$mq)." "; $sql.= "where phone_type_id=".$db->qstr($this->phone_type_id,$mq).""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { $sql= "delete from epi_phone_types "; $sql.= "where phone_type_id=".$db->qstr($this->phone_type_id,$mq).""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_phone_types //################################################################################################ class epi_user_addr { var $user_id; var $addr_id; var $addr_type; var $addr_label; var $company; var $point_of_contact; var $discipline; var $address1; var $address2; var $city; var $state; var $country; var $zip; function epi_user_addr() { $this->user_id = 0; $this->addr_id = 0; $this->addr_type = 0; $this->addr_label = ""; $this->company = ""; $this->point_of_contact = ""; $this->discipline = ""; $this->address1 = ""; $this->address2 = ""; $this->city = ""; $this->state = ""; $this->country = ""; $this->zip = ""; } function get($addr_id,&$db) { $sql= "select user_id,addr_id,addr_type,addr_label,company,point_of_contact,discipline,address1,address2,city,state,country,zip "; $sql.= "from epi_user_addr "; $sql.= "where addr_id=$addr_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->user_id = $row["user_id"]; $this->addr_id = $row["addr_id"]; $this->addr_type = $row["addr_type"]; $this->addr_label = $row["addr_label"]; $this->company = $row["company"]; $this->point_of_contact = $row["point_of_contact"]; $this->discipline = $row["discipline"]; $this->address1 = $row["address1"]; $this->address2 = $row["address2"]; $this->city = $row["city"]; $this->state = $row["state"]; $this->country = $row["country"]; $this->zip = $row["zip"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { //increment table used $next_id = $db->get_next_id(epi_user_addr); $this->addr_id = $next_id; if($this->addr_id > 0) { if($this->addr_type == 0) { //for this to work, the user must be created before the address $sql = "update users set "; $sql.= "company=".$db->qstr($this->company,$mq).","; $sql.= "point_of_contact=".$db->qstr($this->point_of_contact,$mq).","; $sql.= "discipline=".$db->qstr($this->discipline,$mq).","; $sql.= "street1=".$db->qstr($this->address1,$mq).","; $sql.= "street2=".$db->qstr($this->address2,$mq).","; $sql.= "city=".$db->qstr($this->city,$mq).","; $sql.= "state=".$db->qstr($this->state,$mq).","; $sql.= "country=".$db->qstr($this->country,$mq).","; $sql.= "zip=".$db->qstr($this->zip,$mq)." "; $sql.= "where user_id=".$this->user_id.""; $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "insert into epi_user_addr ("; $sql.= "user_id,addr_id,addr_type,addr_label,company,point_of_contact,discipline,address1,address2,city,state,country,zip) "; $sql.= "values ("; $sql.= $this->user_id.","; $sql.= $this->addr_id.","; $sql.= $this->addr_type.","; $sql.= $db->qstr($this->addr_label,$mq).","; $sql.= $db->qstr($this->company,$mq).","; $sql.= $db->qstr($this->point_of_contact,$mq).","; $sql.= $db->qstr($this->discipline,$mq).","; $sql.= $db->qstr($this->address1,$mq).","; $sql.= $db->qstr($this->address2,$mq).","; $sql.= $db->qstr($this->city,$mq).","; $sql.= $db->qstr($this->state,$mq).","; $sql.= $db->qstr($this->country,$mq).","; $sql.= $db->qstr($this->zip,$mq).")"; return ($db->perform_action_query($sql)); }//end of if a new key was returned else { return false; } }//end of function insert function update(&$db,$mq=false) { if($this->addr_type == 0) { $sql = "update users set "; $sql.= "company=".$db->qstr($this->company,$mq).","; $sql.= "point_of_contact=".$db->qstr($this->point_of_contact,$mq).","; $sql.= "discipline=".$db->qstr($this->discipline,$mq).","; $sql.= "street1=".$db->qstr($this->address1,$mq).","; $sql.= "street2=".$db->qstr($this->address2,$mq).","; $sql.= "city=".$db->qstr($this->city,$mq).","; $sql.= "state=".$db->qstr($this->state,$mq).","; $sql.= "country=".$db->qstr($this->country,$mq).","; $sql.= "zip=".$db->qstr($this->zip,$mq)." "; $sql.= "where user_id=".$this->user_id.""; $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "update epi_user_addr set "; $sql.= "user_id=".$this->user_id.","; $sql.= "addr_id=".$this->addr_id.","; $sql.= "addr_type=".$this->addr_type.","; $sql.= "addr_label=".$db->qstr($this->addr_label,$mq).","; $sql.= "company=".$db->qstr($this->company,$mq).","; $sql.= "point_of_contact=".$db->qstr($this->point_of_contact,$mq).","; $sql.= "discipline=".$db->qstr($this->discipline,$mq).","; $sql.= "address1=".$db->qstr($this->address1,$mq).","; $sql.= "address2=".$db->qstr($this->address2,$mq).","; $sql.= "city=".$db->qstr($this->city,$mq).","; $sql.= "state=".$db->qstr($this->state,$mq).","; $sql.= "country=".$db->qstr($this->country,$mq).","; $sql.= "zip=".$db->qstr($this->zip,$mq)." "; $sql.= "where addr_id=".$this->addr_id.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { //if we delete an address... we will delete associated phone numbers //and emails $tables[] = "epi_email_addr"; $tables[] = "epi_phone_addr"; $tables[] = "epi_user_addr"; if($this->addr_type == 0) { $sql = "update users set "; $sql.= "company='',"; $sql.= "point_of_contact='',"; $sql.= "discipline='',"; $sql.= "street1='',"; $sql.= "street2='',"; $sql.= "city='',"; $sql.= "state='',"; $sql.= "country='',"; $sql.= "zip='' "; $sql.= "where users=".$this->user_id.""; $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $answer = true; while(list($k,$v)=each($tables)) { $sql= "delete from ".$v." "; $sql.= "where addr_id=".$this->addr_id.""; if(!($result = $db->perform_action_query($sql)) ) { $answer = false; } }//end of while loop return $answer; }//end of function delete }//end of class epi_user_addr //################################################################################################ class epi_user_emails { var $email_id; var $user_id; var $email; var $email_type; var $email_label; var $email_update_status; function epi_user_emails() { $this->$email_update_status=0; $this->email_id = 0; $this->user_id = 0; $this->email = ""; $this->email_type = 0; $this->email_label = "E-mail"; } function get($email_id,&$db) { $sql= "select email_id,user_id,email,email_type,email_label "; $sql.= "from epi_user_emails "; $sql.= "where email_id=$email_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->email_id = $row["email_id"]; $this->user_id = $row["user_id"]; $this->email = $row["email"]; $this->email_type = $row["email_type"]; $this->email_label = $row["email_label"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert($db,$mq=false) { //------------------------ // Lets check to see if the xame email exists.. // If it does no dice inserting with same // That is Primary email..... // WHY!!! becuase a one user can have primary and sencondary // EMail same.. //-------------------------------- $email_exists=0; $sql="select email,user_id from epi_user_emails where email=".$db->qstr($this->email,$mq). " and email_type=0"; if($result = $db->perform_looping_query($sql)) { //This takes care of JUST PRIMARY EMAILS!!!!!!! if($row = $db->get_next_row($result,MYSQL_ASSOC)){ $email_exists=1; }//end of if row $db->free_result_set($result); } if(!$email_exists){ //Lets check to make sure another user does NOT have it already.. // If it existing and is owned BY anothe user then NO-DICE, cannot have as anmy email $sql="select email,user_id from epi_user_emails where email=".$db->qstr($this->email,$mq) ; if($result = $db->perform_looping_query($sql)) { //This takes care of JUST PRIMARY EMAILS!!!!!!! if($row = $db->get_next_row($result,MYSQL_ASSOC)){ $temp_user_id=$row["user_id"]; if($temp_user_id!=$this->user_id ){ $email_exists=1; } }//end of if row $db->free_result_set($result); } } if(!$email_exists){ //increment table used $next_id = $db->get_next_id(epi_user_emails); $this->email_id = $next_id; if($this->email_id > 0) { if($this->email_type==0) { $sql= "update users set "; $sql.= "email=".$db->qstr($this->email,$mq)." "; $sql.= "where user_id=".$this->user_id; $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "insert into epi_user_emails ("; $sql.= "email_id,user_id,email,email_type,email_label) "; $sql.= "values ("; $sql.= $this->email_id.","; $sql.= $this->user_id.","; $sql.= $db->qstr($this->email,$mq).","; $sql.= $this->email_type.","; $sql.= $db->qstr($this->email_label,$mq).")"; $this->email_update_status=1; return ($db->perform_action_query($sql)); }//end of if a new key was returned else { return false; } } // END of if EMAIL EXISTS }//end of function insert function update(&$db,$mq=false) { //------------------------ // Lets check to see if the dame email exists.. // If it does no dice inserting with same // value //-------------------------------- $email_exists=0; $sql="select email,email_id,user_id from epi_user_emails where email=".$db->qstr($this->email,$mq); //print $sql; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)){ $email_exists=1; $temp_email_id=$row["email_id"]; $temp_user_id=$row["user_id"]; }//end of if row $db->free_result_set($result); } /* if(!$email_exists=0){ //Lets check to make sure another user does NOT have it already.. // If it existing and is owned BY anothe user then NO-DICE, cannot have as anmy email $sql="select email,user_id from epi_user_emails where email=".$db->qstr($this->email,$mq) ; if($result = $db->perform_looping_query($sql)) { //This takes care of JUST PRIMARY EMAILS!!!!!!! if($row = $db->get_next_row($result,MYSQL_ASSOC)){ $temp_user_id=$row["user_id"]; if($temp_user_id!=$this->user_id ){ $email_exists=1; } }//end of if row $db->free_result_set($result); } } */ $can_update=0; //Email exists and it is me... then can update. if($email_exists==1 && $temp_user_id==$this->user_id) { $can_update=1; } //If email does not exist then can update... if($email_exists==0) { $can_update=1; } //What about just updating the lagedlll //print "can_update=$can_update"; if($can_update==1){ if($this->email_type==0) { $sql= "update users set "; $sql.= "email=".$db->qstr($this->email,$mq)." "; $sql.= "where user_id=".$this->user_id; //print $sql; $uresult = $db->perform_action_query($sql); $sql= "update epi_user_emails set "; $sql.= "email=".$db->qstr($this->email,$mq)." "; $sql.= "where user_id=".$this->user_id; $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "update epi_user_emails set "; $sql.= "email_id=".$this->email_id.","; $sql.= "user_id=".$this->user_id.","; $sql.= "email=".$db->qstr($this->email,$mq).","; $sql.= "email_type=".$this->email_type.", "; $sql.= "email_label=".$db->qstr($this->email_label,$mq)." "; $sql.= "where email_id=".$this->email_id.""; $this->email_update_status=1; return ($db->perform_action_query($sql)); // print $sql; } }//end of function update function make_primary(&$db) { //first we make all of the other email addrs secondary $sql= "update epi_user_emails set "; $sql.= "email_type=1 "; $sql.= "where user_id=".$this->user_id." and not(email_id=".$this->email_id.")"; if($result = $db->perform_action_query($sql)) { //now we make this email primary $sql= "update epi_user_emails set "; $sql.= "email_type=0 "; $sql.= "where user_id=".$this->user_id." and email_id=".$this->email_id; $result = $db->perform_action_query($sql); } return $result; }//end of function make_primary function delete(&$db) { $sql= "delete from epi_user_emails "; $sql.= "where email_id=".$this->email_id.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_user_emails //################################################################################################ class epi_user_phone { var $phone_id; var $user_id; var $phone_type; var $phone_type_id; var $phone_number; function epi_user_phone() { $this->phone_id = 0; $this->user_id = 0; $this->phone_type = ""; $this->phone_number = ""; $this->phone_type_id = 0; } function get($phone_id,&$db) { $sql= "select phone_id,user_id,phone_type,phone_number,phone_type_id "; $sql.= "from epi_user_phone "; $sql.= "where phone_id=$phone_id"; $answer = false; if($result = $db->perform_looping_query($sql)) { $answer = true; if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $this->phone_id = $row["phone_id"]; $this->user_id = $row["user_id"]; $this->phone_type = $row["phone_type"]; $this->phone_number = $row["phone_number"]; $this->phone_type_id = $row["phone_type_id"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get function insert(&$db,$mq=false) { //increment table used $next_id = $db->get_next_id(epi_user_phone); $this->phone_id = $next_id; if($this->phone_id > 0) { switch ($this->phone_type_id) { case 0: $sql = "update users set phone=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 1: $sql = "update users set pager=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 2: $sql = "update users set fax=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 3: $sql = "update users set cellular=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; default: $sql = ""; break; }//end of switch case on phone_type_id if($sql != "") { $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "insert into epi_user_phone ("; $sql.= "phone_id,user_id,phone_type,phone_number,phone_type_id) "; $sql.= "values ("; $sql.= $this->phone_id.","; $sql.= $this->user_id.","; $sql.= $db->qstr($this->phone_type,$mq).","; $sql.= $db->qstr($this->phone_number,$mq).","; $sql.= $this->phone_type_id.")"; return ($db->perform_action_query($sql)); }//end of if a new key was returned else { return false; } }//end of function insert function update(&$db,$mq=false) { switch ($this->phone_type_id) { case 0: $sql = "update users set phone=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 1: $sql = "update users set pager=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 2: $sql = "update users set fax=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; case 3: $sql = "update users set cellular=".$db->qstr($this->phone_number,$mq)." where user_id=".$this->user_id; break; default: $sql = ""; break; }//end of switch case on phone_type_id if($sql != "") { $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "update epi_user_phone set "; $sql.= "phone_id=".$this->phone_id.","; $sql.= "user_id=".$this->user_id.","; $sql.= "phone_type=".$db->qstr($this->phone_type,$mq).","; $sql.= "phone_number=".$db->qstr($this->phone_number,$mq).","; $sql.= "phone_type_id=".$this->phone_type_id." "; $sql.= "where phone_id=".$this->phone_id.""; return ($db->perform_action_query($sql)); }//end of function update function delete(&$db) { switch ($this->phone_type_id) { case 0: $sql = "update users set phone='' where user_id=".$this->user_id; break; case 1: $sql = "update users set pager='' where user_id=".$this->user_id; break; case 2: $sql = "update users set fax='' where user_id=".$this->user_id; break; case 3: $sql = "update users set cellular='' where user_id=".$this->user_id; break; default: $sql = ""; break; }//end of switch case on phone_type_id if($sql != "") { $uresult = $db->perform_action_query($sql); }//end of if we need to update the users table $sql= "delete from epi_user_phone "; $sql.= "where phone_id=".$this->phone_id.""; return ($db->perform_action_query($sql)); }//end of function update }//end of class epi_user_phone //################################################################################################ //Miscellaneous global user related functions below here //################################################################################################ function check_login($login,$password,$auth_src,&$db,$mq=false) { $num = 0; if($auth_src == 0) { $sql = "select count(*) as num from users where login=".$db->qstr($login,$mq)." and "; $sql.= " password=".$db->qstr($password,$mq) ; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $num = $row["num"]; }//end of while loop through row $db->free_result_set($result); }//end fo if result }//end of if auth src = 0 //if other authentication source wanted/needed.. send different auth_src and //create else statement //added check to make sure user is active if($num == 1) { $sql = "select user_id,status from users where login=".$db->qstr($login,$mq); $user_id = -1; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { if($row["status"]>=0) { $user_id = $row["user_id"]; } }//end of while loop through row $db->free_result_set($result); }//end of if result return ($user_id); } else { return (-1); } }//end of check_login //################################################################################################# function get_all_user_emails($user_id,&$db) { $sql= "select email_id,user_id,email,email_type,email_label "; $sql.= "from epi_user_emails "; $sql.= "where user_id=$user_id order by email_type"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["email_id"]]->email_id = $row["email_id"]; $answer[$row["email_id"]]->user_id = $row["user_id"]; $answer[$row["email_id"]]->email = $row["email"]; $answer[$row["email_id"]]->email_type = $row["email_type"]; $answer[$row["email_id"]]->email_label = $row["email_label"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of get_all_user_emails function get_all_primary_user_emails($user_id,&$db) { // $sql= "select email_id,user_id,email,email_type,email_label "; // $sql.= "from epi_user_emails "; // $sql.= "where user_id=$user_id and email_type=0 order by email_type"; $sql = "select email from users where user_id='$user_id'"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { // $answer[$row["email_id"]]->email_id = $row["email_id"]; // $answer[$row["email_id"]]->user_id = $row["user_id"]; // $answer[$row["email_id"]]->email = $row["email"]; // $answer[$row["email_id"]]->email_type = $row["email_type"]; // $answer[$row["email_id"]]->email_label = $row["email_label"]; $answer[0]->email = $row["email"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of get_all_user_emails function get_num_user_projects($user_id,&$db,$g_status=1) { $num = 0; $sql = "select count(*) as num from groups as g, realms as r, realm_user as ru "; $sql.= "where g.status=$g_status and r.group_id=g.group_id and r.key_realm=1 and ru.realm_id=r.realm_id and ru.user_id=$user_id "; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $num = $row["num"]; }//end of if row $db->free_result_set($result); }//end of if result return $num; }//end of get_num_user_projects function get_num_projects_user_is_admin($user_id,&$db,$g_status=1) { $num = 0; $sql = "select count(*) as num from groups as g, realms as r, realm_user as ru "; $sql.= "where g.status=$g_status and r.group_id=g.group_id and r.key_realm=2 and ru.realm_id=r.realm_id and ru.user_id=$user_id"; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $num = $row["num"]; }//end of if row $db->free_result_set($result); }//end of if result return $num; }//end of get_num_user_projects function get_primary_email($user_id,&$db) { // NEAR AS WE CAN TELL THE TALBE epi_user_emails is no longer being used // mrc.pxi.com had only 20 users listed in it, when there were over 200 users // in the users table, so we will pull primary email from users table instead // Ryan Gilfether 2/23/06 /* $sql= "select email "; $sql.= "from epi_user_emails "; $sql.= "where user_id=$user_id and email_type=0"; */ $sql = "SELECT email FROM users WHERE user_id=$user_id AND status>-1"; $answer = ""; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer = $row["email"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of get_primary_email function get_primary_email_id($user_id,&$db) { // NEAR AS WE CAN TELL THE TALBE epi_user_emails is no longer being used // mrc.pxi.com had only 20 users listed in it, when there were over 200 users // in the users table, so we will pull primary email from users table instead // Ryan Gilfether 2/23/06 /* $sql= "select email "; $sql.= "from epi_user_emails "; $sql.= "where user_id=$user_id and email_type=0"; */ $sql = "SELECT email FROM users WHERE user_id=$user_id AND status>-1"; $answer = ""; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer = $row["email_id"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of get_primary_email function get_primary_emails_for_group($group_id,&$db) { if($group_id > 0) { $sql = "select distinct(ru.user_id),e.email,e.email_id from "; $sql.= realms." r, ".realm_user. " ru, ".epi_user_emails. "e "; $sql.= "where r.group_id=$group_id and r.key_realm=1 and ru.group_id=r.group_id "; $sql.= "and e.user_id=ru.user_id and e.email_type=0"; } else { $sql = "select distinct(u.user_id),e.email,e.email_id from "; $sql.= "users u, ".epi_user_emails. " e "; $sql.= "where e.user_id=u.user_id and e.email_type=0"; } $answer = array (); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["user_id"]]->email_id = $row["email_id"]; $answer[$row["user_id"]]->email = $row["email"]; }//end of while row $db->free_result_set($result); }//end of if result return $answer; }//end of get_primary_emails_for_group function get_all_user_addrs($user_id,&$db) { $sql= "select user_id,addr_id,addr_label,addr_type,company,point_of_contact,discipline,address1,address2,city,state,country,zip "; $sql.= "from epi_user_addr "; $sql.= "where user_id=$user_id order by addr_type"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["addr_id"]] = new epi_user_addr(); $answer[$row["addr_id"]]->user_id = $row["user_id"]; $answer[$row["addr_id"]]->addr_id = $row["addr_id"]; $answer[$row["addr_id"]]->addr_label = $row["addr_label"]; $answer[$row["addr_id"]]->addr_type = $row["addr_type"]; $answer[$row["addr_id"]]->company = $row["company"]; $answer[$row["addr_id"]]->point_of_contact = $row["point_of_contact"]; $answer[$row["addr_id"]]->discipline = $row["discipline"]; $answer[$row["addr_id"]]->address1 = $row["address1"]; $answer[$row["addr_id"]]->address2 = $row["address2"]; $answer[$row["addr_id"]]->city = $row["city"]; $answer[$row["addr_id"]]->state = $row["state"]; $answer[$row["addr_id"]]->country = $row["country"]; $answer[$row["addr_id"]]->zip = $row["zip"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get_all_user_addrs function get_all_user_phones($user,&$db) { $sql= "select phone_id,user_id,phone_type,phone_number,phone_type_id "; $sql.= "from epi_user_phone "; $sql.= "where user_id=$phone_id"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["phone_id"]]->phone_id = $row["phone_id"]; $answer[$row["phone_id"]]->user_id = $row["user_id"]; $answer[$row["phone_id"]]->phone_type = $row["phone_type"]; $answer[$row["phone_id"]]->phone_type_id = $row["phone_type_id"]; $answer[$row["phone_id"]]->phone_number = $row["phone_number"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get_all_user_phones function get_all_phones_by_address($addr_id,&$db) { $sql= "select up.phone_id as phone_id,up.user_id as user_id,up.phone_type as phone_type,up.phone_type_id as phone_type_id,up.phone_number as phone_number "; $sql.= "from epi_user_phone as up, epi_phone_addr as ap "; $sql.= "where ap.addr_id=$addr_id and up.phone_id=ap.phone_id"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["phone_id"]] = new epi_user_phone(); $answer[$row["phone_id"]]->phone_id = $row["phone_id"]; $answer[$row["phone_id"]]->user_id = $row["user_id"]; $answer[$row["phone_id"]]->phone_type = $row["phone_type"]; $answer[$row["phone_id"]]->phone_type_id = $row["phone_type_id"]; $answer[$row["phone_id"]]->phone_number = $row["phone_number"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get_all_user_phones function get_primary_user_addr_id($user_id,&$db) { $answer = -1; $sql = "select addr_id from epi_user_addr where user_id=$user_id and addr_type=0"; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer = $row["addr_id"]; } $db->free_result_set($result); }//end of if result return ($answer); }//end of get_primary_user_addr_id function get_primary_phones_by_type($user_id,&$db) { $answer = array(); if($addr_id = get_primary_addr_id($user_id,$db)) { $answer = get_all_phones_for_address_by_type($addr_id,$db); } return $answer; }//end of get_primary_phones_by_type function get_all_phones_for_address_by_type($addr_id,&$db) { $sql= "select up.phone_id as phone_id,up.user_id as user_id,up.phone_type as phone_type,up.phone_type_id as phone_type_id,up.phone_number as phone_number "; $sql.= "from epi_user_phone as up, epi_phone_addr as ap "; $sql.= "where ap.addr_id=$addr_id and up.phone_id=ap.phone_id"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["phone_type_id"]]->phone_id = $row["phone_id"]; $answer[$row["phone_type_id"]]->user_id = $row["user_id"]; $answer[$row["phone_type_id"]]->phone_type = $row["phone_type"]; $answer[$row["phone_type_id"]]->phone_type_id = $row["phone_type_id"]; $answer[$row["phone_type_id"]]->phone_number = $row["phone_number"]; }//end of if row $db->free_result_set($result); }//end of if result return ($answer); }//end of function get_all_phones_for_address_by_type function get_all_emails_by_address($addr_id,&$db) { $sql= "select ue.email_id as email_id,ue.user_id as user_id,ue.email as email,ue.email_type as email_type,ue.email_label as email_label "; $sql.= "from epi_user_emails as ue , epi_email_addr as ea "; $sql.= "where ea.addr_id=$addr_id and ue.email_id=ea.email_id order by ue.email_type"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["email_id"]]->email_id = $row["email_id"]; $answer[$row["email_id"]]->user_id = $row["user_id"]; $answer[$row["email_id"]]->email = $row["email"]; $answer[$row["email_id"]]->email_type = $row["email_type"]; $answer[$row["email_id"]]->email_label = $row["email_label"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of get_all_emails_by_address function get_all_phone_types(&$db) { $sql= "select phone_type,order_num,phone_type_id "; $sql.= "from epi_phone_types "; $sql.= "order by order_num"; $answer = array(); if($result = $db->perform_looping_query($sql)) { $i=0; while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["phone_type_id"]]->order_num = $row["order_num"]; $answer[$row["phone_type_id"]]->phone_type = $row["phone_type"]; $answer[$row["phone_type_id"]]->phone_type_id = $row["phone_type_id"]; $i++; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of function get_all_phone_types function get_all_email_types(&$db) { $sql= "select email_type,title "; $sql.= "from epi_email_types "; $sql.= "order by email_type"; $answer = array(); if($result = $db->perform_looping_query($sql)) { $i=0; while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$i]->email_type = $row["email_type"]; $answer[$i]->title = $row["title"]; $i++; }//end of while loop through row $db->free_result_set($result); }//end of if result return $answer; }//end of function get_all_phone_types function get_users_online_in_last_minutes($num_minutes,&$db) { $now = time(); $lastTime = $now - (60*$num_minutes); $num_online = 0; $sql = "select count(*) as num from epi_activity where activity_time > '".$db->time_handler->system2db($lastTime)."'"; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $num_online = $row["num"]; } $db->free_result_set($result); }//end of if result return $num_online; }//end of get_users_online_in_last_minutes function get_user_activity_summary($group_id,&$db) { if(!$group_id > 0) { $group_id = 0; } $sql = "select user_id,activity_time,hit_counter from epi_activity "; $sql.= "where group_id=$group_id"; $answer = array(); if($result = $db->perform_looping_query($sql)) { while($row = $db->get_next_row($result,MYSQL_ASSOC)) { $answer[$row["user_id"]]->activity_time = $db->time_handler->db2system($row["activity_time"]); $answer[$row["user_id"]]->hit_counter = $row["hit_counter"]; } } return $answer; }//end of get_user_activity_summary function get_total_users(&$db,$status="active") { if($status == "active") { $sql = "select count(user_id) as num from users where status>=0"; } else if ($status == "inactive") { $sql = "select count(user_id) as num from users where status=-1"; } else { $sql = "select count(user_id) as num from users"; } $answer = 0; if($result = &$db->perform_looping_query($sql)) { if($row = &$db->get_next_row($result,MYSQL_ASSOC)) { $answer = $row["num"]; }//end of while loop through row $db->free_result_set($result); }//end of if result return ($answer); } //end of function get_total_users function is_new_installation(){ // This will check to see if no users are // registered.. If not return status.. global $db; if(!$db->is_connect_err){ $sql = "select user_id from users"; if($result = $db->perform_looping_query($sql)) { if($row = $db->get_next_row($result,MYSQL_ASSOC)) { $user_id = $row["user_id"]; return 0; } else { return 1; } $db->free_result_set($result); } else { // This is a new install there // are no users that are registered.. // in the users table... return 1; } } else { return 0; } } // END of check_for_new_installation function steal_old_login($db,$login){ if($login!=""){ $sql="select login,user_id from users where login='$login' and status=-1"; //print $sql . "

"; $result = $db->perform_looping_query($sql); if($row = $db->get_next_row($result)) { $temp_user_id=$row["user_id"]; } if($temp_user_id!=""){ // This is not pretty, but will workd. //Because login is unique $garb_date=date("Y_F_j_h:m:s",time()); $sql="update users set login='$garb_date' where user_id=$temp_user_id"; //print $sql . "

"; $result = $db->perform_action_query($sql); } } } function steal_old_email($db,$email){ if($email!="") { $sql="select email,email_id,email_type,user_id from epi_user_emails where " . " email='$email'"; //print $sql . "

"; $result = $db->perform_looping_query($sql); if($row = $db->get_next_row($result)) { $temp_e=$row["email"]; $email_type=$row["email_type"]; $email_id=$row["email_id"]; $temp_user_id=$row["user_id"]; if($temp_e==$email){ $found=1; } } if($found==1){ //OK EMAIL ALREADY EXISTS!!! //Check to see if it is an INACTIVE account $sql="select a.email_id, a.user_id,b.status from epi_user_emails a, users b where " . " email_id='$email_id' and a.user_id=b.user_id"; //print $sql . "

"; $result = $db->perform_looping_query($sql); $status=0; if($row = $db->get_next_row($result)) { $status=$row["status"]; $status= $status + 0; } //END SQL if($status==-1){ //OK delete it..... //ANd if Primary delte from the USERS table as well.. if($email_type==0){ //This email is primary, BLANK it from the users table. $sql="update users set email='' where user_id=$temp_user_id"; $result = $db->perform_action_query($sql); //print $sql . "

"; } $sql="delete from epi_user_emails where email_id=$email_id and user_id=$temp_user_id"; $result = $db->perform_action_query($sql); //Email is not Primary //print $sql . "

"; } } //End if _found } //ENd of IF email NOT BLANK } ?>