[5804] | 1 | <?php
|
---|
| 2 | class Migra{
|
---|
| 3 | public $local;
|
---|
| 4 | public $login;
|
---|
| 5 | public $senha;
|
---|
| 6 | public $banco;
|
---|
| 7 | public $banco2;
|
---|
| 8 | public $porta;
|
---|
| 9 |
|
---|
| 10 | public $current_base;
|
---|
| 11 | public $new_base;
|
---|
| 12 |
|
---|
| 13 | /*
|
---|
| 14 | * TODO - Implementar:
|
---|
| 15 | * Repetição
|
---|
| 16 | * Alarm
|
---|
| 17 | * ACL
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | function __construct()
|
---|
| 21 | {
|
---|
| 22 | include_once dirname(__FILE__ ).'/../../header.inc.php';
|
---|
| 23 |
|
---|
| 24 | if (is_array($_SESSION['phpgw_info']['expresso']['server']))
|
---|
| 25 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
|
---|
| 26 | else
|
---|
| 27 | $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
|
---|
| 28 |
|
---|
| 29 | $local = $_SESSION['phpgw_info']['expresso']['server']['db_host'];
|
---|
| 30 | $login = $_SESSION['phpgw_info']['expresso']['server']['db_user'];
|
---|
| 31 | $senha = $_SESSION['phpgw_info']['expresso']['server']['db_pass'];
|
---|
| 32 | $banco = $_SESSION['phpgw_info']['expresso']['server']['db_name'];
|
---|
| 33 | $porta = $_SESSION['phpgw_info']['expresso']['server']['db_port'];
|
---|
| 34 | $banco2 = $banco;
|
---|
| 35 |
|
---|
| 36 | $this->current_base = pg_connect("host='$local' port='$porta' dbname='$banco' user='$login' password='$senha'");
|
---|
| 37 | $this->new_base = pg_connect("host='$local' port='$porta' dbname='$banco2' user='$login' password='$senha'");
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | //Verifica e/ou cria agenda
|
---|
| 41 | function as_calendar($uid){
|
---|
| 42 | $sql = "select (calendar_id) FROM calendar_signature where user_uidnumber = ".$uid." and is_owner = 1";
|
---|
| 43 | $result = pg_query($this->new_base ,$sql);
|
---|
| 44 | if (!$line = pg_fetch_assoc($result)) {
|
---|
| 45 | $last_resource = pg_query($this->new_base, "insert into calendar (name, location) values('Calendar' , 'Calendar' ) RETURNING id");
|
---|
| 46 | $last = pg_fetch_assoc($last_resource);
|
---|
| 47 |
|
---|
| 48 | $id_resource = pg_query($this->new_base, "insert into calendar_signature(user_uidnumber, calendar_id, is_owner, font_color, background_color, border_color) values(".$uid.", ".$last['id'].", 1, 'FFFFFF', '3366CC', '3366CC') RETURNING id");
|
---|
| 49 | $calendar = pg_fetch_assoc($id_resource);
|
---|
| 50 | return $calendar['id'];
|
---|
| 51 | }else{
|
---|
| 52 | $result = pg_query($this->new_base ,$sql);
|
---|
| 53 | while($evento = pg_fetch_array($result)){
|
---|
| 54 | return $evento['calendar_id'];
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //Usuarios de um evento
|
---|
| 60 | function as_user($cal_id, $calendar_object ,$owner){
|
---|
| 61 | $sql_select_user = "select * from phpgw_cal_user where cal_id = ".$cal_id;
|
---|
| 62 | $result = pg_query($this->current_base ,$sql_select_user);
|
---|
| 63 |
|
---|
| 64 | while($evento = pg_fetch_array($result)){
|
---|
| 65 | $sql_insert = "insert into calendar_participant (user_info_id, object_id, is_organizer, acl ,is_external, participant_status_id) values ( ";
|
---|
| 66 | $sql_insert .= $evento['cal_login'].", ";
|
---|
| 67 | $sql_insert .= $calendar_object.", ";
|
---|
| 68 |
|
---|
| 69 | if ($owner == $evento['cal_login']){
|
---|
| 70 | $sql_insert .= "1, ";
|
---|
| 71 | $sql_insert .= '\'rowi\', ';
|
---|
| 72 | }else{
|
---|
| 73 | $sql_insert .= "0, ";
|
---|
| 74 | $sql_insert .= '\'r\', ';
|
---|
| 75 | }
|
---|
| 76 | $sql_insert .= "0, ";
|
---|
| 77 |
|
---|
| 78 | if($evento['cal_status'] == 'A')
|
---|
| 79 | $sql_insert .= "1) ";
|
---|
| 80 | else if ($evento['cal_status'] == 'U')
|
---|
| 81 | $sql_insert .= "4) ";
|
---|
| 82 | else if ($evento['cal_status'] == 'R')
|
---|
| 83 | $sql_insert .= "3) ";
|
---|
| 84 | else if ($evento['cal_status'] == 'T')
|
---|
| 85 | $sql_insert .= "2) ";
|
---|
| 86 | pg_query($this->new_base ,$sql_insert);
|
---|
| 87 |
|
---|
| 88 | $Id_Calendar_User = $this->as_calendar($evento['cal_login']);
|
---|
| 89 | $sql_insert_relcao = 'insert into calendar_to_calendar_object (calendar_id, calendar_object_id) values ( ';
|
---|
| 90 | $sql_insert_relcao .= $Id_Calendar_User.', ';
|
---|
| 91 | $sql_insert_relcao .= $calendar_object.' )';
|
---|
| 92 | pg_query($this->new_base ,$sql_insert_relcao);
|
---|
| 93 |
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | //Alarmes de um evento
|
---|
| 97 | function as_alarm($cal_id, $date_ini, $date_end){
|
---|
| 98 | $sql_select_evento = "select * from phpgw_async where id like '%".$cal_id."%'";
|
---|
| 99 | $result = pg_query($this->current_base ,$sql_select_evento);
|
---|
| 100 |
|
---|
| 101 | while($evento = pg_fetch_array($result)){
|
---|
| 102 | if(!$result['account_id'])
|
---|
| 103 | continue;
|
---|
| 104 | $sql_insert = "insert into calendar_alarm (action_id, time, range_end, range_start, unit, participant_id, object_id,sent) values ( ";
|
---|
| 105 | //action_id
|
---|
| 106 | $sql_insert .= "1, ";
|
---|
| 107 |
|
---|
| 108 | //time
|
---|
| 109 | $time = split (":", $result['times']);
|
---|
| 110 | $sql_insert .= substr($time, -1).", ";
|
---|
| 111 | //range_end
|
---|
| 112 | $sql_insert .= "'".$date_end."', ";
|
---|
| 113 | //range_start
|
---|
| 114 | $sql_insert .= "'".$date_ini."', ";
|
---|
| 115 | //arrumar unit
|
---|
| 116 | $sql_insert .= "1, ";
|
---|
| 117 | //participant_id
|
---|
| 118 | $sql_insert .= $result['account_id'].", ";
|
---|
| 119 | //object_id
|
---|
| 120 | $sql_insert .= $cal_id.", ";
|
---|
| 121 | //sent
|
---|
| 122 | if($date_ini > time())
|
---|
| 123 | $sql_insert .= "0 ) ";
|
---|
| 124 | else
|
---|
| 125 | $sql_insert .= "1 ) ";
|
---|
| 126 |
|
---|
| 127 | pg_query($this->new_base ,$sql_insert);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | //Usuarios externos de um evento
|
---|
| 132 | function as_user_external($cal_id, $calendar_object ,$owner, $ex_participante){
|
---|
| 133 |
|
---|
| 134 | $participants_ex = base64_decode($ex_participante);
|
---|
| 135 | //Participantes externos serializados
|
---|
| 136 | try {
|
---|
| 137 | $participants_ex = unserialize($participants_ex);
|
---|
| 138 | foreach ($participants_ex as $ex){
|
---|
| 139 |
|
---|
| 140 | $sql_insert = "insert into calendar_ex_participant (name, mail, owner) values ( ";
|
---|
| 141 | if(array_key_exists('cn', $ex))
|
---|
| 142 | $sql_insert .= "'".$ex['cn']."', ";
|
---|
| 143 | else
|
---|
| 144 | $sql_insert .= "'', ";
|
---|
| 145 | $sql_insert .= "'".$ex['mail']."', ";
|
---|
| 146 | $sql_insert .= $owner.") RETURNING id";
|
---|
| 147 |
|
---|
| 148 | $result = pg_query($this->new_base ,$sql_insert);
|
---|
| 149 |
|
---|
| 150 | $id_external = pg_fetch_assoc($result);
|
---|
| 151 | $sql_insert = "insert into calendar_participant (user_info_id, object_id, is_organizer, is_external, participant_status_id) values ( ";
|
---|
| 152 | $sql_insert .= $id_external['id'].", ";
|
---|
| 153 | $sql_insert .= $calendar_object.", ";
|
---|
| 154 | $sql_insert .= "0, ";
|
---|
| 155 | $sql_insert .= "1, ";
|
---|
| 156 | $sql_insert .= "4 ) ";
|
---|
| 157 |
|
---|
| 158 | pg_query($this->new_base ,$sql_insert);
|
---|
| 159 | }
|
---|
| 160 | //participantes externos normais
|
---|
| 161 | } catch (Exception $e) {
|
---|
| 162 | $participants_ex = split(',', $ex_participante);
|
---|
| 163 |
|
---|
| 164 | foreach ($participants_ex as $ex){
|
---|
| 165 | $sql_insert = "insert into calendar_ex_participant (mail, owner) values ( ";
|
---|
| 166 | $sql_insert .= "'".$ex."', ";
|
---|
| 167 | $sql_insert .= $owner.") RETURNING id";
|
---|
| 168 |
|
---|
| 169 | $result = pg_query($this->new_base ,$sql_insert);
|
---|
| 170 |
|
---|
| 171 | $id_external = pg_fetch_assoc($result);
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | $sql_insert = "insert into calendar_participant (user_info_id, object_id, is_organizer, is_external, participant_status_id) values ( ";
|
---|
| 175 | $sql_insert .= $id_external['id'].", ";
|
---|
| 176 | $sql_insert .= $calendar_object.", ";
|
---|
| 177 | $sql_insert .= "0, ";
|
---|
| 178 | $sql_insert .= "1, ";
|
---|
| 179 | $sql_insert .= "4 ) ";
|
---|
| 180 | pg_query($this->new_base ,$sql_insert);
|
---|
| 181 |
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | //
|
---|
| 187 | function calendar(){
|
---|
| 188 | $sql = "SELECT * FROM phpgw_cal";
|
---|
| 189 | //Todo
|
---|
| 190 | //Implementar Repetição
|
---|
| 191 |
|
---|
| 192 | $result = pg_query($this->current_base, $sql);
|
---|
| 193 | while($evento = pg_fetch_array($result)){
|
---|
| 194 |
|
---|
| 195 | $sql_insert = "insert into calendar_object
|
---|
| 196 | (
|
---|
| 197 | type_id, cal_uid, dtstamp,
|
---|
| 198 | dtstart, description, dtend,
|
---|
| 199 | location, class_id, last_update,
|
---|
| 200 | range_end, range_start,
|
---|
| 201 | summary, allday, repeat, tzid
|
---|
| 202 | )
|
---|
| 203 |
|
---|
| 204 | values(";
|
---|
| 205 | //remove lixos
|
---|
| 206 | if($evento['owner'] == 0)
|
---|
| 207 | continue;
|
---|
| 208 | if($evento['mdatetime'] == "" or $evento['mdatetime'] == null)
|
---|
| 209 | continue;
|
---|
| 210 | if($evento['datetime'] == "" or $evento['datetime'] == null)
|
---|
| 211 | continue;
|
---|
| 212 | if($evento['edatetime'] == "" or $evento['edatetime'] == null)
|
---|
| 213 | continue;
|
---|
| 214 | //type_id
|
---|
| 215 | $sql_insert .= "1, ";
|
---|
| 216 | //cal_uid
|
---|
| 217 | $sql_insert .= "'".mt_rand()."@Expresso', ";
|
---|
| 218 | //$sql_insert .= $this->as_calendar($evento['owner']).", ";
|
---|
| 219 | //dtstamp
|
---|
| 220 | $sql_insert .= $evento['mdatetime']."000, ";
|
---|
| 221 | //dtstart
|
---|
| 222 | $sql_insert .= $evento['datetime']."000, ";
|
---|
| 223 | //description
|
---|
| 224 | if ($evento['description'] == "" or $evento['description'] == null)
|
---|
| 225 | $sql_insert .= "'', ";
|
---|
| 226 | else
|
---|
| 227 | $sql_insert .= "'".$evento['description']."', ";
|
---|
| 228 | //dtend
|
---|
| 229 | $sql_insert .= $evento['edatetime']."000, ";
|
---|
| 230 | //location
|
---|
| 231 | if ($evento['location'] == "" or $evento['location'] == null)
|
---|
| 232 | $sql_insert .= "'', ";
|
---|
| 233 | else
|
---|
| 234 | $sql_insert .= "'".$evento['location']."', ";
|
---|
| 235 | //class_id
|
---|
| 236 | if($evento['is_public'] == 1){
|
---|
| 237 | if($evento['cal_type'] == 'e')
|
---|
| 238 | $sql_insert .= "1, ";
|
---|
| 239 | else
|
---|
| 240 | $sql_insert .= "3, ";
|
---|
| 241 | }else
|
---|
| 242 | $sql_insert .= "2, ";
|
---|
| 243 | //last_update
|
---|
| 244 | $sql_insert .= $evento['last_update'].", ";
|
---|
| 245 | //range_end
|
---|
| 246 | $sql_insert .= "'".$evento['edatetime']."', ";
|
---|
| 247 | //calendar_id
|
---|
| 248 | //$sql_insert .= $this->as_calendar($evento['owner']).", ";
|
---|
| 249 | //range_start
|
---|
| 250 | $sql_insert .= "'".$evento['datetime']."', ";
|
---|
| 251 | //summary
|
---|
| 252 | if ($evento['title'] == "" or $evento['title'] == null)
|
---|
| 253 | $sql_insert .= "'', ";
|
---|
| 254 | else
|
---|
| 255 | $sql_insert .= "'".$evento['title']."', ";
|
---|
| 256 | //allday
|
---|
| 257 | $sql_insert .= "0, ";
|
---|
| 258 | //repeat
|
---|
| 259 | $sql_insert .= "0, ";
|
---|
| 260 | //tzid
|
---|
| 261 | $sql_insert .= "'America/Sao_Paulo'";
|
---|
| 262 |
|
---|
| 263 | $sql_insert .= " ) RETURNING id";
|
---|
| 264 |
|
---|
| 265 | $last_resource = pg_query($this->new_base, $sql_insert);
|
---|
| 266 | $calendar = pg_fetch_assoc($last_resource);
|
---|
| 267 |
|
---|
| 268 | //participantes de um evento
|
---|
| 269 | $this->as_user($evento['cal_id'] ,$calendar['id'], $evento['owner']);
|
---|
| 270 |
|
---|
| 271 | //participantes externos de um evento
|
---|
| 272 | if($evento['ex_participants'] != "" and $evento['ex_participants'] != 'YTowOnt9')
|
---|
| 273 | $this->as_user_external($evento['cal_id'] ,$calendar['id'], $evento['owner'], $evento['ex_participants']);
|
---|
| 274 |
|
---|
| 275 | //Por equanto desativado
|
---|
| 276 | //$this->as_alarm($evento['cal_id'], $evento['datetime'],$evento['edatetime']) ;
|
---|
| 277 |
|
---|
| 278 | }
|
---|
| 279 | return 'sucesss';
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | ?> |
---|