You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php require_once('../ajax_asm.php'); if( $CUser->Data['id'] > 1 && $CUser->Data['access'] > 5 ){ $Data = array(); $Data['success'] = false; if( isset( $_POST['OPID'] ) ){ $CMD = intval( $_POST['OPID'] ); } else { $CMD = 0; }; if( isset( $_POST['ID'] ) ){ $OID = intval( $_POST['ID'] ); } else { $OID = 0; }; if( $CMD > 0 ){ switch( $CMD ){ case 1:{//Add Platform
if( strlen( $_POST['OPCODE'] ) ){ $GOGA = json_decode( $_POST['OPCODE'], true ); $NAME = $DATABASE->escape( $GOGA['NAME'] ); $SHORT = $DATABASE->escape( $GOGA['SHORT'] ); $COLOR = str_ireplace( '#', '', $DATABASE->escape( $GOGA['COLOR'] ) ); $TYPE = intval($GOGA['TYPE']); $QS = "INSERT INTO `metro_lines`(`color`,`status`,`name`,`short`,`type`) VALUES('{$COLOR}','D','{$NAME}','{$SHORT}',{$type})"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 2:{//Delete Platform
if( $OID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; $PARAM = intval( $_POST['OPCODE'] ); if( $PARAM ){ $QS = "SELECT `id` FROM `metro_lines` WHERE `id`={$PARAM}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $QS = "DELETE FROM `metro_stations_2_lines` WHERE `line_id`={$PARAM}"; $DATABASE->Query( $QS ); $QS = "DELETE FROM `metro_platforms_2_lines` WHERE `line_id`={$PARAM}"; $DATABASE->Query( $QS ); $QS = "DELETE FROM `metro_lines` WHERE `id`={$PARAM}"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { // No Such Line
}; } else { // No Line ID
}; break; }; case 3:{//Bind Station to a Line
if( $OID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( isset( $_POST['OPCODE'] ) ){ $LID = intval( $_POST['OPCODE'] ); if( $LID ){ $QS="SELECT count(`station_id`) `cnt` FROM `metro_stations_2_lines` WHERE `line_id`={$LID}"; $Result = $DATABASE->Query( $QS ); if( count( $Result ) ) { $IDX = intval( $Result[0]['cnt'] )+1; } else $IDX = 1; $QS = "INSERT INTO `metro_stations_2_lines`(`station_id`,`line_id`,`index`) VALUES({$OID},{$LID},{$IDX})"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 4:{//Unbind Station from Line
if( $OID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( isset( $_POST['OPCODE'] ) ){ $LID = intval( $_POST['OPCODE'] ); if( $LID ){ $QS="DELETE FROM `metro_stations_2_lines` WHERE `line_id`={$LID} AND `station_id`={$OID}"; $DATABASE->Query( $QS ); $QS = "SELECT `station_id`, `index` FROM `metro_stations_2_lines` WHERE `line_id`={$LID} ORDER BY `index`"; $LL = $DATABASE->Query( $QS ); $IDX = 1; foreach( $LL as $L ){ $QS="UPDATE `metro_stations_2_lines` SET `index`={$IDX} WHERE `line_id`={$LID} AND `station_id`={$L['station_id']}"; $DATABASE->Query( $QS ); $IDX++; }; $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 5:{//Move Station On Line Z.
if( $OID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( isset( $_POST['OPCODE'] ) ){ $GOGA = json_decode( $_POST['OPCODE'], true ); $LID = intval( $GOGA['LINE'] ); $DIR = intval( $GOGA['DIR'] ); if( $LID ){ $QS = "SELECT `index` FROM `metro_stations_2_lines` WHERE `line_id`={$LID} AND `station_id`={$OID}"; $Result = $DATABASE->Query( $QS ); if( count( $Result ) ) { $CIDX = intval( $Result[0]['index'] ); $QS = "SELECT `station_id`, `index` FROM `metro_stations_2_lines` WHERE `line_id`={$LID} ORDER BY `index`"; $LL = $DATABASE->Query( $QS ); foreach( $LL as $L ){ if( $DIR ){ if( $L['station_id'] == $OID ){ $L['index'] = $CIDX-1; if( $L['index'] < 1 ) $L['index'] = 1; } else { if( $L['index']==($CIDX-1) ){ $L['index']++; }; }; } else { if( $L['station_id'] == $OID ){ $L['index'] = $CIDX+1; } else { if( $L['index']==($CIDX+1) ){ $L['index']--; if( $L['index'] < 1 ) $L['index'] = 1; }; }; }; $QS = "UPDATE `metro_stations_2_lines` SET `index`={$L['index']} WHERE `line_id`={$LID} AND `station_id`={$L['station_id']}"; $DATABASE->Query( $QS ); }; $Data['success'] = true; $LOG->reg_op( $_POST ); }; } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); } } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 6:{//Update Name
if( $LID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( strlen( $_POST['OPCODE'] ) ){ $NAME = $DATABASE->escape( $_POST['OPCODE'] ); $QS = "UPDATE `metro_lines` SET `name`='{$NAME}' WHERE `id`={$LID}"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 7:{//Update Short
if( $LID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( strlen( $_POST['OPCODE'] ) ){ $SHORT = $DATABASE->escape( $_POST['OPCODE'] ); $QS = "UPDATE `metro_lines` SET `short`='{$SHORT}' WHERE `id`={$LID}"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 8:{//Update Color
if( $LID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( strlen( $_POST['OPCODE'] ) ){ $COLOR = str_ireplace( '#', '', $DATABASE->escape( $_POST['OPCODE'] ) ); $QS = "UPDATE `metro_lines` SET `color`='{$COLOR}' WHERE `id`={$LID}"; $DATABASE->Query( $QS ); $Data['success'] = true; $LOG->reg_op( $_POST ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 9:{//Update type
if( $LID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; $PARAM = intval( $_POST['OPCODE'] ); if( $PARAM ){ $QS = "UPDATE `metro_lines` SET `type`={$PARAM} WHERE `id`={$LID}"; $DATABASE->Query( $QS ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; case 10:{//Update ena/dis
if( $LID == 0 ) { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; if( isset( $_POST['OPCODE'] ) ){ $PARAM = intval( $_POST['OPCODE'] ); $QS = ($PARAM)?"UPDATE `metro_lines` SET `status`='E' WHERE `id`={$LID}":"UPDATE `metro_lines` SET `status`='D' WHERE `id`={$LID}"; $DATABASE->Query( $QS ); } else { $Data['msg']='Wrong Parameters!'; echo json_encode( $Data ); exit(); }; break; }; }; } else { $Data['msg']='Wrong Parameters!'; }; echo json_encode( $Data ); exit(); } else { $LOG->security_treat( $_POST ); }; header('location: /');?>
|