Skip to content
Permalink
Browse files

first alpha

  • Loading branch information...
Anisan committed Sep 29, 2019
0 parents commit 86d35139cbdd1f76089f1de2c482eb551e8faf4c
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -0,0 +1,115 @@
<?php
/*
* @version 0.1 (wizard)
*/
if ($this->owner->name=='panel') {
$out['CONTROLPANEL']=1;
}
$table_name='sonoff_diy_devices';
$rec=SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
if ($this->mode=='update') {
$ok=1;
// step: default
if ($this->tab=='') {
//updating '<%LANG_TITLE%>' (varchar, required)
$rec['TITLE']=gr('title');
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
}
//updating '<%LANG_UPDATED%>' (datetime)
global $updated_date;
global $updated_minutes;
global $updated_hours;
$rec['UPDATED']=toDBDate($updated_date)." $updated_hours:$updated_minutes:00";
}
// step: data
if ($this->tab=='data') {
}
//UPDATING RECORD
if ($ok) {
if ($rec['ID']) {
SQLUpdate($table_name, $rec); // 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['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==$updated_hours) {
$out['UPDATED_HOURS'][]=array('TITLE'=>$title, 'SELECTED'=>1);
} else {
$out['UPDATED_HOURS'][]=array('TITLE'=>$title);
}
}
}
// step: data
if ($this->tab=='data') {
}
if ($this->tab=='data') {
//dataset2
$new_id=0;
global $delete_id;
if ($delete_id) {
SQLExec("DELETE FROM sonoff_diy_data WHERE ID='".(int)$delete_id."'");
}
$properties=SQLSelect("SELECT * FROM sonoff_diy_data WHERE DEVICE_ID='".$rec['ID']."' ORDER BY ID");
$total=count($properties);
for($i=0;$i<$total;$i++) {
if ($properties[$i]['ID']==$new_id) continue;
if ($this->mode=='update') {
global ${'title'.$properties[$i]['ID']};
$properties[$i]['TITLE']=trim(${'title'.$properties[$i]['ID']});
global ${'value'.$properties[$i]['ID']};
$properties[$i]['VALUE']=trim(${'value'.$properties[$i]['ID']});
global ${'linked_object'.$properties[$i]['ID']};
$properties[$i]['LINKED_OBJECT']=trim(${'linked_object'.$properties[$i]['ID']});
global ${'linked_property'.$properties[$i]['ID']};
$properties[$i]['LINKED_PROPERTY']=trim(${'linked_property'.$properties[$i]['ID']});
global ${'linked_method'.$properties[$i]['ID']};
$properties[$i]['LINKED_METHOD']=trim(${'linked_method'.$properties[$i]['ID']});
SQLUpdate('sonoff_diy_data', $properties[$i]);
$old_linked_object=$properties[$i]['LINKED_OBJECT'];
$old_linked_property=$properties[$i]['LINKED_PROPERTY'];
if ($old_linked_object && $old_linked_object!=$properties[$i]['LINKED_OBJECT'] && $old_linked_property && $old_linked_property!=$properties[$i]['LINKED_PROPERTY']) {
removeLinkedProperty($old_linked_object, $old_linked_property, $this->name);
}
if ($properties[$i]['LINKED_OBJECT'] && $properties[$i]['LINKED_PROPERTY']) {
addLinkedProperty($properties[$i]['LINKED_OBJECT'], $properties[$i]['LINKED_PROPERTY'], $this->name);
}
}
}
$out['PROPERTIES']=$properties;
}
if (is_array($rec)) {
foreach($rec as $k=>$v) {
if (!is_array($v)) {
$rec[$k]=htmlspecialchars($v);
}
}
}
outHash($rec, $out);
@@ -0,0 +1,32 @@
<?php
/*
* @version 0.1 (wizard)
*/
global $session;
if ($this->owner->name=='panel') {
$out['CONTROLPANEL']=1;
}
$qry="1";
// search filters
// QUERY READY
global $save_qry;
if ($save_qry) {
$qry=$session->data['sonoff_diy_devices_qry'];
} else {
$session->data['sonoff_diy_devices_qry']=$qry;
}
if (!$qry) $qry="1";
$sortby_sonoff_diy_devices="ID DESC";
$out['SORTBY']=$sortby_sonoff_diy_devices;
// SEARCH RESULTS
$res=SQLSelect("SELECT * FROM sonoff_diy_devices WHERE $qry ORDER BY ".$sortby_sonoff_diy_devices);
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;
}
@@ -0,0 +1,33 @@
<?php
chdir(dirname(__FILE__) . '/../');
include_once("./config.php");
include_once("./lib/loader.php");
include_once("./lib/threads.php");
set_time_limit(0);
// connecting to database
$db = new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME);
include_once("./load_settings.php");
include_once(DIR_MODULES . "control_modules/control_modules.class.php");
$ctl = new control_modules();
include_once(DIR_MODULES . 'sonoff_diy/sonoff_diy.class.php');
$sonoff_diy_module = new sonoff_diy();
$sonoff_diy_module->getConfig();
echo date("H:i:s") . " running " . basename(__FILE__) . PHP_EOL;
$latest_check=0;
$checkEvery=0; // poll every 5 seconds
while (1)
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
if ((time()-$latest_check)>$checkEvery) {
$latest_check=time();
//echo date('Y-m-d H:i:s')." Polling devices...\n";
$sonoff_diy_module->processCycle();
}
if (file_exists('./reboot') || IsSet($_GET['onetime']))
{
$db->Disconnect();
exit;
}
//sleep(1);
}
DebMes("Unexpected close of cycle: " . basename(__FILE__));
@@ -0,0 +1,103 @@
<div>
<a href="https://github.com/itead/Sonoff_Devices_DIY_Tools/blob/master/SONOFF%20DIY%20MODE%20Protocol%20Doc%20v1.4.md">
<img src="/img/modules/sonoff_diy.png" width="24" height="24"></a>&nbsp;Sonoff DIY Mode
&nbsp;

[#if CYCLERUN==1#]
<span class="label label-success" title="Статус цикла">Цикл запущен</span>
[#else#]
<span class="label label-danger" title="Статус цикла">Цикл остановлен</span>
[#endif#]
<button class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#about">About&nbsp;&nbsp;<span class="glyphicon glyphicon-info-sign icon-white"></span>
</button>
</div>

<!-- action usual -->
[#if DATA_SOURCE="sonoff_diy_devices" || DATA_SOURCE=""#]
<!-- table sonoff_diy_devices search -->
[#if VIEW_MODE="search_sonoff_diy_devices" || VIEW_MODE=""#]
[#inc sonoff_diy_devices_search_admin.html#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_devices search -->
<!-- table sonoff_diy_devices edit -->
[#if VIEW_MODE="edit_sonoff_diy_devices"#]
[#if ID!=""#]
[#if TITLE!=""#]<h4>[#TITLE#]</h4>[#endif TITLE#]
<ul class="nav nav-tabs">
<li[#if TAB=""#] class="active"[#endif#]>
<a href="?data_source=<#DATA_SOURCE#>&view_mode=<#VIEW_MODE#>&id=<#ID#>&tab="><#LANG_GENERAL#></a>
</li>
<li[#if TAB="data"#] class="active"[#endif#]>
<a href="?data_source=<#DATA_SOURCE#>&view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=data">&#060#LANG_DATA#&#062</a>
</li>
</ul>
&nbsp;<br/>
[#endif ID#]
[#if TAB=""#]
[#inc sonoff_diy_devices_edit_default.html#]
[#endif TAB#]
[#if TAB="data"#]
[#inc sonoff_diy_devices_edit_data.html#]
[#endif TAB#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_devices edit -->
<!-- table sonoff_diy_devices view -->
[#if VIEW_MODE="view_sonoff_diy_devices"#]
[#if TAB=""#]
[#inc sonoff_diy_devices_view_default.html#]
[#endif TAB#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_devices view -->
[#endif DATA_SOURCE#]
<!-- action usual -->
[#if DATA_SOURCE="sonoff_diy_data"#]
<!-- table sonoff_diy_data search -->
[#if VIEW_MODE="search_sonoff_diy_data" || VIEW_MODE=""#]
[#inc sonoff_diy_data_search_admin.html#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_data search -->
<!-- table sonoff_diy_data edit -->
[#if VIEW_MODE="edit_sonoff_diy_data"#]
[#inc sonoff_diy_data_edit.html#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_data edit -->
<!-- table sonoff_diy_data view -->
[#if VIEW_MODE="view_sonoff_diy_data"#]
[#inc sonoff_diy_data_view.html#]
[#endif VIEW_MODE#]
<!-- / table sonoff_diy_data view -->
[#endif DATA_SOURCE#]

<div class="modal fade" id="about" tabindex="-1" role="dialog" aria-labelledby="about1" aria-hidden="true">
<!-- <div id="about" class="modal hide"> -->
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Sonoff DIY</h4>
</div>
<div class="modal-body">
<div class="float-right">
<img src="/img/modules/sonoff_diy.png" width="48" height="48">
</div>
<p class="float-left"> Sonoff DIY.<br>
Обсуждение модуля <a href="http://majordomo.smartliving.ru/forum/viewtopic.php?f=5" target="_blank">здесь</a>.<br>
</p>
<hr size="1">
<p class="float-left">
Поддержать автора материально:
<ul>
<li>Yandex: <a href="https://money.yandex.ru/to/410012076838296/100" target="_blank">410012076838296</a></li>
<li>WebMoney: R366396529511</li>
<li><a href="https://connect.smartliving.ru/profile/186" target="_blank">Connect</a></li>
</ul>
</p>
</div>

<div class="modal-footer">
<div class="pull-left">Telegram: <a href="https://telegram.me/Eraser1981" target="_blank">@Eraser1981</a> :)</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@@ -0,0 +1 @@
<!--# Action Usual #-->
@@ -0,0 +1,9 @@

[#if ACTION=""#]
<!-- Frontend -->
[#inc action_usual.html#]
[#endif#]
[#if ACTION="admin"#]
<!-- Control Panel -->
[#inc action_admin.html#]
[#endif#]
@@ -0,0 +1,61 @@

<!-- Table 'sonoff_diy_devices' edit -->
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
[#if OK#]
<div class="alert alert-success"><#LANG_DATA_SAVED#></div>
[#endif OK#]
[#if ERR#]
<div class="alert alert-danger"><#LANG_FILLOUT_REQURED#></div>
[#endif ERR#]
<fieldset>
[#if ID=""#]
<legend><#LANG_NEW_RECORD#></legend>
[#endif ID#]
<div class="form-group">
<div>
<table class="table table-stripped">
<tr>
<td><#LANG_TITLE#></td>
<td><#LANG_VALUE#></td>
<td><#LANG_LINKED_OBJECT#></td>
<td><#LANG_LINKED_PROPERTY#></td>
<td><#LANG_METHOD#></td>
<td valign="top"><#LANG_UPDATED#></td>
<td>&nbsp;</td>
</tr>
[#begin PROPERTIES#]
<tr>
<td valign="top"><input type="text" name="title[#ID#]" id="title[#ID#]" value="[#TITLE#]"></td>
<td valign="top"><input type="text" name="value[#ID#]" id="value[#ID#]" value="[#VALUE#]"></td>
<td valign="top"><input type="text" name="linked_object[#ID#]" id="linked_object[#ID#]" value="[#LINKED_OBJECT#]"></td>
<td valign="top"><input type="text" name="linked_property[#ID#]" id="linked_property[#ID#]" value="[#LINKED_PROPERTY#]"></td>
<td valign="top"><input type="text" name="linked_method[#ID#]" id="linked_method[#ID#]" value="[#LINKED_METHOD#]"></td>
[#module name="linkedobject" object_field="linked_object<#PROPERTIES.ID#>" property_field="linked_property<#PROPERTIES.ID#>" method_field="linked_method<#PROPERTIES.ID#>" width="200"#]
<td valign="top">[#UPDATED#]</td>
<td><a href="?id=<#ID#>&tab=<#TAB#>&view_mode=<#VIEW_MODE#>&delete_id=[#ID#]" onClick="return confirm('<#LANG_ARE_YOU_SURE#>');" class="btn btn-default"><i class="glyphicon glyphicon-remove"></i></td>
</tr>
[#end PROPERTIES#]
</table>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-3 col-lg-4">
[#if ID!=""#]
<button type="submit" name="subm" value="Submit" class="btn btn-primary"><#LANG_SUBMIT#></button>
[#else ID#]
<button type="submit" name="subm" value="Add" class="btn btn-primary"><#LANG_ADD#></button>
[#endif ID#]
<a href="?data_source=<#DATA_SOURCE#>" class="btn btn-default "><#LANG_CANCEL#></a>
<input type="hidden" name="id" value="<#ID#>">
<input type="hidden" name="view_mode" value="<#VIEW_MODE#>">
<input type="hidden" name="edit_mode" value="<#EDIT_MODE#>">
<input type="hidden" name="mode" value="update">
<input type="hidden" name="data_source" value="<#DATA_SOURCE#>">
<input type="hidden" name="tab" value="<#TAB#>">
</div>
</div>
</fieldset>
</form>
<!-- dataset2 (module) -->
<div class="form-group">
</div>

0 comments on commit 86d3513

Please sign in to comment.
You can’t perform that action at this time.