<?php
/**
 * Screen alerts\live
 * @version 1.0.1
 * @package Backend\Alerts
 * 
*/

$context = $this->data["contextname"];
$list = $this->data['list'];
$lcontext = $this->data['contexts'];
$lstatus = $this->data['status'];

?>
<div class="row" >
<div class="col-lg-12" >
            <h3><?= R('page_title_alerts') ?></h3>  
	         <BR>         
           	  <form name="form1" method="post" action="<?= __SITEBASE ?>/alerts/save">        
            
             <div class="panel panel-default">
	         <div class="panel-body">
           	 <div class="table-responsive" >
           	        <table  id="table1" class="table table-hover table-striped tablesorter">
           	 <thead>
                  <tr>
                    <th class="header"><?=R('label_date') ?> <i class="fa fa-sort"></i></th>
                    <th class="header"><?=R("type") ?> <i class="fa fa-sort"></i></th>
                    <th class="header"><?=R('label_value') ?> <i class="fa fa-sort"></i></th>
                    <th class="header"><?= R("status") ?></th>
                  </tr>
                </thead>
                <tbody>
                <?php
                foreach($list as $line)  { ?>
                  <tr <?php if(isset($line->alert_contextid)) { ?> onclick="window.location.href='<?= __SITEBASE.'/'.str_replace(__ALERT_CONTEXTID_TAG,$line->alert_contextid,$line->alerttype_navigationcontexto) ?>&<?= Navigation::NEXTKEY.'=alerts' ?>'" <?php } ?>>
                  	 <td>
                    	<?=substr($line->alert_creationdate,0,16); ?>
                	</td>
                    <td>
                    	<?=  ($line->alertcontexttype_descriptioncode != '') ? D($line->alertcontexttype_descriptioncode) : ' - ' ?>
                	</td>
                    <td>
                    	<?= str_replace(__ALERT_CONTEXTDESC_TAG,(isset($line->alert_contextdescription))?$line->alert_contextdescription :$line->alert_contextid ,D($line->alerttype_descriptioncode)); ?>
                	</td>
                 <td>
                    	<?php 
                    	$name =  $line->alert_id;  	 
						?>
                    		<select class="form-control" name="alertstatus_<?= $name ?>" id="alertstatus_<?= $name ?>" onclick="event.stopPropagation();" onchange="javascript:$('#changed_<?= $name ?>').val('1');" >
								  <?php 
								  foreach ($lstatus as $ls) { ?>
								  			<option value="<?=$ls->id ?>" <?=($ls->id == $line->alert_statuscodeid)?  ' selected="selected" ' : '' ?>><?= print_field(D($ls->descriptioncode),'text') ?></option>
								  <?php } ?>
								</select>
                    		<input type="hidden" value="" id="changed_<?= $name ?>" name="changed_<?= $name?>">
                	                    
                   	</td>  
                        	
                  </tr>
               <?php
                  }
                ?>
                </tbody>
              </table>

              
           	 
              </div>
              </div>
              </div>
	              <div>
		              <button class="btn  btn-default" onclick="window.location.href='<?= __SITEBASE.'/'.$context ?>/newndp<?=$this->data['page']?>'"><?= R('btn_save')?></button>
		              <a href="<?= __SITEBASE ?>/alerts" class="btn btn-default" role="button"><?= R('btn_cancel') ?></a>
		              <div class="pull-right">
		              	<a href="<?= __SITEBASE ?>/alerts/history" class="btn btn-default" role="button"><?= R('btn_history') ?></a> 
		              </div>
	              </div>
               </form>
	</div>
</div> 
          