Esempio n. 1
0
File: User.php Progetto: spinit/osy
 public function update($uid, $origin = 'app')
 {
     switch ($origin) {
         case 'osy':
             $user = $this->dba->exec_unique("SELECT o_lbl AS nam,e.p_vl AS eml,o_nam AS lgn,r.o_4 as rul,a.p_vl AS is_act,u.o_id\n                                                 FROM osy_obj u\n                                                 INNER JOIN osy_obj_rel r ON (u.o_id = r.o_3)\n                                                 LEFT JOIN osy_obj_prp e ON (u.o_id = e.o_id AND e.p_id = 'email')\n                                                 LEFT JOIN osy_obj_prp a ON (u.o_id = a.o_id AND a.p_id = 'is-active')\n                                                 WHERE u.o_id = ?", array($uid), 'NUM');
             break;
         default:
             $user = $this->dba->exec_unique("SELECT nam,eml,lgn,rul,is_act,id\n                                                 FROM osy_user\n                                                 WHERE id = ?", array($uid), 'NUM');
             break;
     }
     $stringConnection = $this->dbo->exec_query("SELECT a.p_1 as cn\n                                                  FROM osy_obj_rel r\n                                                  INNER JOIN osy_obj_rel a ON (r.o_1 = a.o_1 AND r.o_2 = a.o_2 AND a.r_typ = 'instance+application')\n                                                  WHERE r.r_typ = 'user+role'\n                                                    AND r.o_3 = ?", array($user[5]));
     foreach ($stringConnection as $rec) {
         $db = DbFactory::dbConnectionByString($rec['cn']);
         if ($db && $db->get_type() != 'oracle') {
             try {
                 $n = $db->exec_unique("SELECT count(*) FROM osy_user WHERE id = ?", array($uid));
                 if ($n > 0) {
                     $db->exec_cmd("UPDATE osy_user SET\n                                        nam = ?,\n                                        eml = ?,\n                                        lgn = ?,\n                                        rol = ?,\n                                        is_act = ?\n                                       WHERE id = ?", $user);
                 } else {
                     $db->exec_cmd("INSERT INTO osy_user \n                                        (nam,eml,lgn,rol,is_act,id) \n                                        VALUES \n                                      (?,?,?,?,?,?)", $user);
                 }
             } catch (Exception $e) {
                 switch ($e->getCode()) {
                     case '42S02':
                         //No break
                     //No break
                     case '42P01':
                         echo $e->getMessage();
                         break;
                 }
                 echo $e->getMessage();
             }
         }
     }
 }