index.php 8.13 KB
Newer Older
1 2 3
<?
include_once("common_includes.php");

4 5 6 7 8
$DEFPANELS = array();
$DEFPANELS[]=array('panel_title'=>'grandstream_left','panel_websections'=>'_grandstream_left','panel_type'=>'gxv3175_left','panel_content'=>'*')+$PANELDEFAULTS;
$DEFPANELS[]=array('panel_title'=>'grandstream_center','panel_websections'=>'_grandstream_center','panel_type'=>'gxv3175_center','panel_content'=>'*')+$PANELDEFAULTS;
$DEFPANELS[]=array('panel_title'=>'grandstream_right','panel_websections'=>'_grandstream_right','panel_type'=>'gxv3175_right','panel_content'=>'*')+$PANELDEFAULTS;

9 10 11 12 13 14 15 16 17
$colors=array(
   'gray' => 'pure-button-active',
   'blue' =>  'pure-button-primary', 
   'azure' =>  'pure-button-secondary',
   'green' =>  'pure-button-success',
   'red' => 'pure-button-error',
   'orange' => 'pure-button-warning'
);

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
$panels=DB::query("SELECT * FROM user_gui_panels WHERE user='$_DOMOTIKA[username]' AND page='gmi' ORDER by panel_position,id");
if(!$panels or count($panels)<1) {
   $panels=$DEFPANELS;
   foreach($panels as $p) {
      $q="INSERT INTO user_gui_panels 
         (user,page,panel_title,panel_type,panel_cols,panel_height,panel_visible,panel_position,panel_sections,panel_websections,panel_selector,panel_content)
         VALUES
         ('".$_DOMOTIKA['username']."','gmi','".$p['panel_title']."','".$p['panel_type']."',
            '".$p['panel_cols']."','".$p['panel_height']."','".$p['panel_visible']."','".$p['panel_position']."',
            '".$p['panel_sections']."','".$p['panel_websections']."','".$p['panel_selector']."','".$p['panel_content']."')";
      DB::query($q);
   }
}
foreach($panels as $panel) {
      switch($panel['panel_type'])
      {
         case 'gxv3175_left':
            $buttonar_left=getPanelButtons($_DOMOTIKA['username'], $panel['panel_content'], $panel['panel_sections'], $panel['panel_websections'], $panel['panel_selector'],true,7);
            break;
         case 'gxv3175_center':
            $buttonar_center=getPanelButtons($_DOMOTIKA['username'], $panel['panel_content'], $panel['panel_sections'], $panel['panel_websections'], $panel['panel_selector'],true,7);
            break;
         case 'gxv3175_right':
            $buttonar_right=getPanelButtons($_DOMOTIKA['username'], $panel['panel_content'], $panel['panel_sections'], $panel['panel_websections'], $panel['panel_selector'],true,7);
            break;
      }
}

//$buttonar_left=getPanelButtons($_DOMOTIKA['username'], "*","*","_grandstream_left", "dmdomain","true",7);
//$buttonar_right=getPanelButtons($_DOMOTIKA['username'], "*","*","_grandstream_right", "dmdomain","true",7);
48
//print_r($buttonar_left);
49
?>
nextime's avatar
nextime committed
50 51
<html>
<head>
nextime's avatar
nextime committed
52
<title>Domotika GMI Interface</title>
53
<link rel="stylesheet" href="/resources/pure/pure-nr-min.css">
54
<link rel="stylesheet" href="/resources/fontawesome/css/font-awesome.min.css">
nextime's avatar
nextime committed
55
<link href='style.css' type='text/css' rel='stylesheet'>
nextime's avatar
nextime committed
56
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
57 58 59 60 61 62
<!--
<script src="/resources/js/sockjs-0.3.min.js" ></script>
<script src="/resources/js/ajaxsocket.js" ></script>
-->
<script src="/resources/js/jquery-1.9.0.min.js"></script>
<script src="/resources/EventSource/eventsource.js"></script>
63
<script language="javascript" src="simpleGMI.js"></script> 
nextime's avatar
nextime committed
64
<script type="text/javascript">
65

nextime's avatar
nextime committed
66
simpleGMI.fullScreen();
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

/**
 * jQuery alterClass plugin
 *
 * Remove element classes with wildcard matching. Optionally add classes:
 *   $( '#foo' ).alterClass( 'foo-* bar-*', 'foobar' )
 *
 * Copyright (c) 2011 Pete Boere (the-echoplex.net)
 * Free under terms of the MIT license: http://www.opensource.org/licenses/mit-license.php
 *
 */
(function ( $ ) {
$.fn.alterClass = function ( removals, additions ) {
   var self = this;
   if ( removals.indexOf( '*' ) === -1 ) {
      // Use native jQuery methods if there is no wildcard matching
      self.removeClass( removals );
      return !additions ? self : self.addClass( additions );
   }
   var patt = new RegExp( '\\s' +
         removals.
            replace( /\*/g, '[A-Za-z0-9-_]+' ).
            split( ' ' ).
            join( '\\s|\\s' ) +
         '\\s', 'g' );
   self.each( function ( i, it ) {
      var cn = ' ' + it.className + ' ';
      while ( patt.test( cn ) ) {
         cn = cn.replace( patt, ' ' );
      }
      it.className = $.trim( cn );
   });
   return !additions ? self : self.addClass( additions );
};
})( jQuery );

function postreply(arg)
{
   alert(arg);
}
/*
var clicksound = new Audio("/domotika/gmi/beep.wav");
clicksound.preload = 'auto';
clicksound.load();

function playClick(volume) {
  var click=clicksound.cloneNode();
  click.volume=volume;
  click.play();
}*/

function butpushed(btype, bid)
119
{
120
   //playClick(1);
121
   //simpleGMI.play('/domotika/gmi/beep.wav',0,0,function(data){alert(data)});
122
   $.post("/rest/v1.2/"+btype+"/setbyid/"+bid+"/json");
123
}
124

125
setInterval(function(){
126
   simpleGMI.post('http://q.unixmedia.net/domotika/gmi/style.css', 'aaa=sarca', postreply);
127
}, 5000);
nextime's avatar
nextime committed
128
</script>
nextime's avatar
nextime committed
129 130
</head>
<body>
131 132 133 134
<div class="pure-g" >
   <div class="pure-u-1-3" style="padding-left:1.3333%;">
      <?
         foreach($buttonar_left as $but) {
135 136 137 138
            if(intval($but['status'])==1)
               $bcolor=$colors[$but['color_on']];
            else
               $bcolor=$colors[$but['color_off']];
139 140
      ?> 
         <div style="padding:5px;">
141
            <button class="pure-button <?=$bcolor?>" data-dm-type="<?=$but['devtype']?>-<?=$but['id']?>" data-dmcolor-on="<?=$colors[$but['color_on']]?>" data-dmcolor-off="<?=$colors[$but['color_off']]?>" style="width:100%;height:50px;" onclick="butpushed('<?=$but['devtype']?>',<?=$but['id']?>)"><?=$but['button_name']?></button>
142 143 144 145
         </div>
      <?
         }
      ?>
146
   </div>
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
   <div class="pure-u-1-3" style="width:31%">
      <div style="padding:5px;">
         <button class="pure-button pure-button-primary" style="width:100%;height:130px;" onclick="simpleGMI.refresh()">test</button>
      </div>
      <div style="height:80px" onclick="simpleGMI.refresh()">
      </div>
      <div style="padding:5px;display:none">
         <img src="https://192.168.4.45/enu/camera320x240.jpg" style="width:100%;height:190px" onclick="simpleGMI.refresh()"></img>
      </div>
      <div style="padding:5px;">
         <div class="pure-g">
            <div class="pure-u-1-3" >
               <button class="pure-button"><h1>15</h1></button>
            </div>
            <div class="pure-u-1-3" style="width:28%">
               <button class="pure-button"><h1>:</h1></button>
            </div>
            <div class="pure-u-1-3" >
               <button class="pure-button"><h1>15</h1></button>
            </div>
         </div>
      </div>   

nextime's avatar
nextime committed
170

171
   </div>
172 173 174
   <div class="pure-u-1-3" >
      <?
         foreach($buttonar_right as $but) {
175 176 177 178 179
            if(intval($but['status'])==1)
               $bcolor=$colors[$but['color_on']];
            else
               $bcolor=$colors[$but['color_off']];

180 181
      ?>
         <div style="padding:5px;">
182
            <button class="pure-button <?=$bcolor?>" data-dm-type="<?=$but['devtype']?>-<?=$but['id']?>" data-dmcolor-on="<?=$colors[$but['color_on']]?>" data-dmcolor-off="<?=$colors[$but['color_off']]?>" style="width:100%;height:50px;" onclick="butpushed('<?=$but['devtype']?>',<?=$but['id']?>)"><?=$but['button_name']?></button>
183 184 185 186
         </div>
      <?
         }
      ?>
187 188 189 190 191 192
   </div>

</div>

<div class="footer-bar">
<button onClick="simpleGMI.dial(0, 0, 0, 281, '', 1)" class="pure-button pure-button-secondary">
193 194 195 196 197
   <i class="fa fa-microphone fa-2x blackiconcolor"></i>
</button>
<span> STATUS: DEFAULT</span>
<button onClick="simpleGMI.refresh()" class="pure-button pure-button-secondary" style="float:right">
   <i class="fa fa-refresh fa-2x fa-spin blackiconcolor"></i>
198 199 200
</button>

</div>
201 202 203 204 205 206
<script>
var es = new EventSource("/sse");

var syncReceived = function(event) {
   var res=$.parseJSON(event.data);
   $.each(res.data.statuses, function(idx, val){
207 208 209 210 211 212 213 214 215 216
      console.debug(val);
      $("[data-dm-type="+val[3]+"s-"+val[0]+"]").each(
         function() {
            if(val[1]==1)
               var color=$(this).attr('data-dmcolor-on');
            else
               var color=$(this).attr('data-dmcolor-off');
            $(this).alterClass('pure-button-*', color);
         }
      )
217 218 219 220
   });
}
es.addEventListener("sync", syncReceived);
</script>
nextime's avatar
nextime committed
221 222
</body>
</html>