} else {
            $new_rec = 1;
            $rec['ID'] = SQLInsert($table_name, $rec);
            // adding new record
        }
        $out['OK'] = 1;
    } else {
        $out['ERR'] = 1;
    }
}
if ($rec['DUE'] != '') {
    $rec['DUE'] = fromDBDate($rec['DUE']);
}
if ($rec['ADDED'] != '') {
    $tmp = explode(' ', $rec['ADDED']);
    $out['ADDED_DATE'] = fromDBDate($tmp[0]);
    $tmp2 = explode(':', $tmp[1]);
    $added_hours = $tmp2[0];
    $added_minutes = $tmp2[1];
}
for ($i = 0; $i < 60; $i++) {
    $title = $i;
    if ($i < 10) {
        $title = "0{$i}";
    }
    if ($title == $added_minutes) {
        $out['ADDED_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
    } else {
        $out['ADDED_MINUTES'][] = array('TITLE' => $title);
    }
}
    $session->data['ssdp_devices_qry'] = $qry;
}
if (!$qry) {
    $qry = "1";
}
//="ID DESC";
//$out['SORTBY']=$sortby_ssdp_devices;
// SEARCH RESULTS
$res = Scan();
if ($res[0]['ID']) {
    //paging($res, 100, $out); // search result paging
    $total = count($res);
    for ($i = 0; $i < $total; $i++) {
        // some action for every record if required
        $tmp = explode(' ', $res[$i]['UPDATED']);
        $res[$i]['UPDATED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
    }
    $out['RESULT'] = $res;
}
function Scan()
{
    $upnp = new Upnp();
    print 'searching...' . PHP_EOL;
    $everything = $upnp->discover();
    $result = [];
    foreach ($everything as $device) {
        //print_r($device);  //uncomment to see all available array elements for a device.
        $info = $device['description']['device'];
        // print array_search(, array_column( $result, 'ADDRESS'));
        if (!array_search_result($result, 'UUID', $info["UDN"])) {
            $result[] = ["ID" => $info["UDN"], "TITLE" => $info["friendlyName"], "ADDRESS" => $info["presentationURL"], "UUID" => $info["UDN"], "DESCRIPTION" => is_array($info["modelDescription"]) ? implode(',', $info["modelDescription"]) : $info["modelDescription"], "TYPE" => explode(":", $info["deviceType"])[3], "LOGO" => getDefImg($info), "SERIAL" => $info["serialNumber"], "MANUFACTURERURL" => $info["manufacturerURL"], "UPDATED" => '', "MODEL" => $info["modelName"], "MANUFACTURER" => $info["manufacturer"], "IP" => getIp($info)];
if (!$qry) {
    $qry = "1";
}
// FIELDS ORDER
global $sortby_system_errors;
if (!$sortby_system_errors) {
    $sortby_system_errors = $session->data['system_errors_sort'];
} else {
    if ($session->data['system_errors_sort'] == $sortby_system_errors) {
        if (Is_Integer(strpos($sortby_system_errors, ' DESC'))) {
            $sortby_system_errors = str_replace(' DESC', '', $sortby_system_errors);
        } else {
            $sortby_system_errors = $sortby_system_errors . " DESC";
        }
    }
    $session->data['system_errors_sort'] = $sortby_system_errors;
}
$sortby_system_errors = "ACTIVE DESC, LATEST_UPDATE DESC, CODE";
$out['SORTBY'] = $sortby_system_errors;
// SEARCH RESULTS
$res = SQLSelect("SELECT * FROM system_errors WHERE {$qry} ORDER BY " . $sortby_system_errors);
if ($res[0]['ID']) {
    colorizeArray($res);
    $total = count($res);
    for ($i = 0; $i < $total; $i++) {
        // some action for every record if required
        $tmp = explode(' ', $res[$i]['LATEST_UPDATE']);
        $res[$i]['LATEST_UPDATE'] = fromDBDate($tmp[0]) . " " . $tmp[1];
    }
    $out['RESULT'] = $res;
}
}
//options for 'USER_ID' (select)
$tmp = SQLSelect("SELECT ID, NAME FROM users ORDER BY NAME");
$users_total = count($tmp);
for ($users_i = 0; $users_i < $users_total; $users_i++) {
    $user_id_opt[$tmp[$users_i]['ID']] = $tmp[$users_i]['NAME'];
}
for ($i = 0; $i < $users_total; $i++) {
    if ($rec['USER_ID'] == $tmp[$i]['ID']) {
        $tmp[$i]['SELECTED'] = 1;
    }
}
$out['USER_ID_OPTIONS'] = $tmp;
if ($rec['UPDATED'] != '') {
    $tmp = explode(' ', $rec['UPDATED']);
    $out['UPDATED_DATE'] = fromDBDate($tmp[0]);
    $tmp2 = explode(':', $tmp[1]);
    $updated_hours = $tmp2[0];
    $updated_minutes = $tmp2[1];
}
for ($i = 0; $i < 60; $i++) {
    $title = $i;
    if ($i < 10) {
        $title = "0{$i}";
    }
    if ($title == $updated_minutes) {
        $out['UPDATED_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
    } else {
        $out['UPDATED_MINUTES'][] = array('TITLE' => $title);
    }
}
    }
}
for ($i = 0; $i < 24; $i++) {
    $title = $i;
    if ($i < 10) {
        $title = "0{$i}";
    }
    if ($title == $check_latest_hours) {
        $out['CHECK_LATEST_HOURS'][] = array('TITLE' => $title, 'SELECTED' => 1);
    } else {
        $out['CHECK_LATEST_HOURS'][] = array('TITLE' => $title);
    }
}
if ($rec['CHECK_NEXT'] != '') {
    $tmp = explode(' ', $rec['CHECK_NEXT']);
    $out['CHECK_NEXT_DATE'] = fromDBDate($tmp[0]);
    $tmp2 = explode(':', $tmp[1]);
    $check_next_hours = $tmp2[0];
    $check_next_minutes = $tmp2[1];
}
for ($i = 0; $i < 60; $i++) {
    $title = $i;
    if ($i < 10) {
        $title = "0{$i}";
    }
    if ($title == $check_next_minutes) {
        $out['CHECK_NEXT_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
    } else {
        $out['CHECK_NEXT_MINUTES'][] = array('TITLE' => $title);
    }
}
  }
  if (!$qry) $qry="1";
  // FIELDS ORDER
  global $sortby_calendar_events;
  if (!$sortby_calendar_events) {
   $sortby_calendar_events=$session->data['calendar_events_sort'];
  } else {
   if ($session->data['calendar_events_sort']==$sortby_calendar_events) {
    if (Is_Integer(strpos($sortby_calendar_events, ' DESC'))) {
     $sortby_calendar_events=str_replace(' DESC', '', $sortby_calendar_events);
    } else {
     $sortby_calendar_events=$sortby_calendar_events." DESC";
    }
   }
   $session->data['calendar_events_sort']=$sortby_calendar_events;
  }
  if (!$sortby_calendar_events) $sortby_calendar_events="ID DESC";
  $out['SORTBY']=$sortby_calendar_events;
  // SEARCH RESULTS
  $res=SQLSelect("SELECT * FROM calendar_events WHERE $qry ORDER BY ".$sortby_calendar_events);
  if ($res[0]['ID']) {
   paging($res, 50, $out); // search result paging
   colorizeArray($res);
   $total=count($res);
   for($i=0;$i<$total;$i++) {
    // some action for every record if required
    $res[$i]['DUE']=fromDBDate($res[$i]['DUE']);
   }
   $out['RESULT']=$res;
  }
?>
global $sortby_gpslog;
if (!$sortby_gpslog) {
    $sortby_gpslog = $session->data['gpslog_sort'];
} else {
    if ($session->data['gpslog_sort'] == $sortby_gpslog) {
        if (Is_Integer(strpos($sortby_gpslog, ' DESC'))) {
            $sortby_gpslog = str_replace(' DESC', '', $sortby_gpslog);
        } else {
            $sortby_gpslog = $sortby_gpslog . " DESC";
        }
    }
    $session->data['gpslog_sort'] = $sortby_gpslog;
}
if (!$sortby_gpslog) {
    $sortby_gpslog = "gpslog.ID DESC";
}
$out['SORTBY'] = $sortby_gpslog;
// SEARCH RESULTS
$res = SQLSelect("SELECT gpslog.*, gpsdevices.TITLE as DEVICE_TITLE, gpslocations.TITLE as LOCATION_TITLE FROM gpslog LEFT JOIN gpsdevices ON gpsdevices.ID=gpslog.DEVICE_ID LEFT JOIN gpslocations ON gpslocations.ID=gpslog.LOCATION_ID WHERE {$qry} ORDER BY " . $sortby_gpslog);
if ($res[0]['ID']) {
    paging($res, 50, $out);
    // search result paging
    colorizeArray($res);
    $total = count($res);
    for ($i = 0; $i < $total; $i++) {
        // some action for every record if required
        $tmp = explode(' ', $res[$i]['ADDED']);
        $res[$i]['ADDED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
    }
    $out['RESULT'] = $res;
}
}
//options for 'SCRIPT_ID' (select)
$tmp = SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
$scripts_total = count($tmp);
for ($scripts_i = 0; $scripts_i < $scripts_total; $scripts_i++) {
    $script_id_opt[$tmp[$scripts_i]['ID']] = $tmp[$scripts_i]['TITLE'];
}
for ($i = 0; $i < $scripts_total; $i++) {
    if ($rec['SCRIPT_ID'] == $tmp[$i]['ID']) {
        $tmp[$i]['SELECTED'] = 1;
    }
}
$out['SCRIPT_ID_OPTIONS'] = $tmp;
if ($rec['EXECUTED'] != '') {
    $tmp = explode(' ', $rec['EXECUTED']);
    $out['EXECUTED_DATE'] = fromDBDate($tmp[0]);
    $tmp2 = explode(':', $tmp[1]);
    $executed_hours = $tmp2[0];
    $executed_minutes = $tmp2[1];
}
for ($i = 0; $i < 60; $i++) {
    $title = $i;
    if ($i < 10) {
        $title = "0{$i}";
    }
    if ($title == $executed_minutes) {
        $out['EXECUTED_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
    } else {
        $out['EXECUTED_MINUTES'][] = array('TITLE' => $title);
    }
}
Beispiel #9
0
    $sortby = $session->data['events_sort'];
} else {
    if ($session->data['events_sort'] == $sortby) {
        if (Is_Integer(strpos($sortby, ' DESC'))) {
            $sortby = str_replace(' DESC', '', $sortby);
        } else {
            $sortby = $sortby . " DESC";
        }
    }
    $session->data['events_sort'] = $sortby;
}
if (!$sortby) {
    $sortby = "ID DESC";
}
$out['SORTBY'] = $sortby;
// SEARCH RESULTS
$res = SQLSelect("SELECT * FROM events WHERE {$qry} ORDER BY {$sortby}");
if ($res[0]['ID']) {
    paging($res, 50, $out);
    // search result paging
    colorizeArray($res);
    $total = count($res);
    for ($i = 0; $i < $total; $i++) {
        // some action for every record if required
        $tmp = explode(' ', $res[$i]['ADDED']);
        $res[$i]['ADDED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
        $tmp = explode(' ', $res[$i]['EXPIRE']);
        $res[$i]['EXPIRE'] = fromDBDate($tmp[0]) . " " . $tmp[1];
    }
    $out['RESULT'] = $res;
}
            // update
        } else {
            $new_rec = 1;
            $rec['ID'] = SQLInsert($table_name, $rec);
            // adding new record
        }
        $out['OK'] = 1;
    } else {
        $out['ERR'] = 1;
    }
}
// step: default
if ($this->tab == '') {
    if ($rec['LATEST_UPDATE'] != '') {
        $tmp = explode(' ', $rec['LATEST_UPDATE']);
        $out['LATEST_UPDATE_DATE'] = fromDBDate($tmp[0]);
        $tmp2 = explode(':', $tmp[1]);
        $latest_update_hours = $tmp2[0];
        $latest_update_minutes = $tmp2[1];
    }
    for ($i = 0; $i < 60; $i++) {
        $title = $i;
        if ($i < 10) {
            $title = "0{$i}";
        }
        if ($title == $latest_update_minutes) {
            $out['LATEST_UPDATE_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
        } else {
            $out['LATEST_UPDATE_MINUTES'][] = array('TITLE' => $title);
        }
    }
if (!$qry) {
    $qry = "1";
}
// FIELDS ORDER
global $sortby_gpsactions;
if (!$sortby_gpsactions) {
    $sortby_gpsactions = $session->data['gpsactions_sort'];
} else {
    if ($session->data['gpsactions_sort'] == $sortby_gpsactions) {
        if (Is_Integer(strpos($sortby_gpsactions, ' DESC'))) {
            $sortby_gpsactions = str_replace(' DESC', '', $sortby_gpsactions);
        } else {
            $sortby_gpsactions = $sortby_gpsactions . " DESC";
        }
    }
    $session->data['gpsactions_sort'] = $sortby_gpsactions;
}
$sortby_gpsactions = "gpsactions.LOCATION_ID, gpsactions.USER_ID, ACTION_TYPE";
$out['SORTBY'] = $sortby_gpsactions;
// SEARCH RESULTS
$res = SQLSelect("SELECT gpsactions.*, gpslocations.TITLE as LOCATION_TITLE, users.NAME as USER_NAME, scripts.TITLE as SCRIPT_TITLE FROM gpsactions LEFT JOIN gpslocations ON gpslocations.ID=gpsactions.LOCATION_ID LEFT JOIN users ON gpsactions.USER_ID=users.ID LEFT JOIN scripts ON scripts.ID=gpsactions.SCRIPT_ID WHERE {$qry} ORDER BY " . $sortby_gpsactions);
if ($res[0]['ID']) {
    colorizeArray($res);
    $total = count($res);
    for ($i = 0; $i < $total; $i++) {
        // some action for every record if required
        $tmp = explode(' ', $res[$i]['EXECUTED']);
        $res[$i]['EXECUTED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
    }
    $out['RESULT'] = $res;
}
  } else {
   $out['ADDED_MINUTES'][]=array('TITLE'=>$title);
  }
 }
 for($i=0;$i<24;$i++) {
  $title=$i;
  if ($i<10) $title="0$i";
  if ($title==$added_hours) {
   $out['ADDED_HOURS'][]=array('TITLE'=>$title, 'SELECTED'=>1);
  } else {
   $out['ADDED_HOURS'][]=array('TITLE'=>$title);
  }
 }
 if ($rec['EXPIRE']!='') {
  $tmp=explode(' ', $rec['EXPIRE']);
  $out['EXPIRE_DATE']=fromDBDate($tmp[0]);
  $tmp2=explode(':', $tmp[1]);
  $expire_hours=$tmp2[0];
  $expire_minutes=$tmp2[1];
 }
 for($i=0;$i<60;$i++) {
  $title=$i;
  if ($i<10) $title="0$i";
  if ($title==$expire_minutes) {
   $out['EXPIRE_MINUTES'][]=array('TITLE'=>$title, 'SELECTED'=>1);
  } else {
   $out['EXPIRE_MINUTES'][]=array('TITLE'=>$title);
  }
 }
 for($i=0;$i<24;$i++) {
  $title=$i;