linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file common.php

Documentation is available at common.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage dashboard
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. function getPositionfromValue ($value, $indicator, $threshold_value){
  12.     if ($indicator['sdii_max_value']==0) {
  13.         $max_value=0.000001;
  14.     } else {
  15.         $max_value=$indicator['sdii_max_value'];
  16.     }
  17.     if ($indicator['sdii_min_value']==0) {
  18.         $min_value=0.000001;
  19.     } else {
  20.         $min_value=$indicator['sdii_min_value'];
  21.     }
  22.     if ($indicator['sdii_threshold_relative']=='Y') {
  23.         $unitup    = 50 / ($max_value - $threshold_value);
  24.         $unitdown    = 50 / ( $threshold_value - $min_value);
  25.         if ($value > $threshold_value) $result = 50 + (($value - $threshold_value) *$unitup);
  26.         else $result = 50 -( ($threshold_value - $value ) *$unitdown );
  27.     }
  28.     else{
  29.         if(($max_value - $threshold_value) <> 0) $unitdown = 50 / ($max_value - $threshold_value);
  30.         if(($threshold_value - $min_value) <> 0) $unitup = 50 / ($threshold_value - $min_value);
  31.         if ($value > $threshold_value) $result=50 -( ($value - $threshold_value) * $unitdown);
  32.         else $result = 50 + (( $threshold_value - $value ) * $unitup);
  33.     }
  34.     return (int)$result;
  35. }
  36.  
  37.  
  38. function getIndicatorInfoBox($current_value, $indicator, $threshold_value, $class= '') {
  39.  
  40.     $content =     "<div class=\"indicator-info ".$class."\"><p>".ucfirst(_t('dashboard','value'))." : <strong>".$current_value." (".formatText($indicator['sdii_unit']).")</strong></p>".
  41.             "<p>".ucfirst(_t('sdi','min_value'))." : <strong>".empty_nc($indicator['sdii_min_value'])."</strong></p>".
  42.             "<p>".ucfirst(_t('sdi','max_value'))." : <strong>".empty_nc($indicator['sdii_max_value'])."</strong></p>".
  43.             "<p>".ucfirst(_t('sdi','threshold_value'))." : <strong>".empty_nc($threshold_value)."</strong></p>".
  44.             "</div>";
  45.  
  46.     return $content;
  47. }
  48.  
  49. function getGaugeViz($sql_object, $scale_id, $indicator, $threshold_value, $cursorcssposition) {
  50.     
  51.     //$cursorcssposition is used to adjust cursor position depending on the container/context
  52.  
  53.     $req_sdiav=SQL_getAllValue("SCA", $scale_id, $indicator['sdii_id']);
  54.     $result_value = $sql_object -> DBSelect($req_sdiav);
  55.  
  56.     // values are stored
  57.     if ($result_value<>false){
  58.         $value_cursor1 = getPositionfromValue ($result_value[0]['sdiv_value'], $indicator, $threshold_value);
  59.         $value_cursor = 111 - $value_cursor1 + $cursorcssposition;
  60.     }
  61.     else {
  62.         $value_cursor = 0;
  63.     }
  64.  
  65.     // there is no value
  66.     if ($result_value==false) {
  67.  
  68.         $gauge= 'gauge_grey.gif';
  69.         $current_value = _t('dashboard','novalue');
  70.         $cursor_visibility = 'hidden';
  71.         $class="indicator-no-data";
  72.  
  73.     }
  74.     // min, max and threshold are not set together. No display allowed
  75.     elseif(is_null($indicator['sdii_max_value']) || is_null($indicator['sdii_min_value']) || is_null($threshold_value)) {
  76.  
  77.         $gauge= 'gauge_red.gif';
  78.         $current_value = $result_value[0]['sdiv_value'];
  79.         $cursor_visibility = 'hidden';
  80.         $class="indicator-no-cursor";
  81.  
  82.     }
  83.     // there is at leat one value and min, max and threshold are set together
  84.     else {
  85.  
  86.         $gauge= 'gauge.gif';
  87.         $current_value = $result_value[0]['sdiv_value'];
  88.         $cursor_visibility = 'visible';
  89.         $class="";
  90.  
  91.     }
  92.     
  93.     if(CURRENT_APP == 'admin') {
  94.         $link = "index.php?rub=dashboard&amp;todo=det&amp;id=".$indicator['sdii_id']."&amp;scale_id=".$scale_id;
  95.     } else {
  96.         $link = HrefMaker(array('rub'=> $GLOBALS['links'][U_L]['dashboard']['linkvalue'],'id'=>$indicator['sdii_id'], 'parentid'=> $scale_id));
  97.     }
  98.  
  99.     $listing =    "<div class=\"dashboard-indicator-gauge indicator-info-container\">
  100.     <a href=\"".$link."\" class=\"infobox\">
  101.     <img src=\"" .THEME_ADMIN_PATH. "images/".$gauge."\" alt=\"".ucfirst(_t('dashboard','value'))." : ".$current_value." (".formatText($indicator['sdii_unit']).") ".
  102.     "\n ".ucfirst(_t('sdi','min_value'))." : ".empty_nc($indicator['sdii_min_value']).
  103.     "\n ".ucfirst(_t('sdi','max_value'))." : ".empty_nc($indicator['sdii_max_value']).
  104.     "\n ".ucfirst(_t('sdi','threshold_value'))." : ".empty_nc($threshold_value)."\"  /></a>";
  105.     $listing .= getIndicatorInfoBox($current_value, $indicator, $threshold_value, $class);
  106.     $listing .= "<img src=\"" .THEME_ADMIN_PATH. "images/cursor.gif\" title=\""._t('dashboard','value')." : ". $current_value ." ". formatText($indicator['sdii_unit']) . " - "._t('dashboard','barre')."\" class=\"cursor\" style=\"visibility:".$cursor_visibility.";left:-".$value_cursor."px;\"/>";
  107.  
  108.  
  109.     $listing .= getTendency($result_value);
  110.  
  111.     $listing .= "\t<span class=\"value\"> (".strtolower($current_value).")</span>\n";
  112.     $listing .= "\t</div>\n";
  113.  
  114.     return     $listing;
  115. }
  116.  
  117. function getRawViz($sql_object, $scale_id, $indicator, $threshold_value) {
  118.  
  119.     $req_sdiav=SQL_getAllValue("SCA", $scale_id, $indicator['sdii_id']);
  120.     $result_value = $sql_object -> DBSelect($req_sdiav);
  121.  
  122.     $str = '<div class="dashboard-indicator-raw">';
  123.  
  124.     // there is no value
  125.     if ($result_value==false) {
  126.         $str .= '<span class="infobox no-value">-</span>';
  127.         $current_value = _t('dashboard','novalue');
  128.         $class="indicator-no-data";
  129.         // some values are there
  130.     } else {
  131.         $str .= '<span class="infobox value">'.$result_value[0]['sdiv_value'].'</span>';
  132.         $current_value = $result_value[0]['sdiv_value'];
  133.         $class="";
  134.     }
  135.     $str .= getIndicatorInfoBox($current_value, $indicator, $threshold_value, $class);
  136.  
  137.     $str .= '<span class="unit">'.formatText($indicator['sdii_unit']).'</span>';
  138.     $str .= '</div>';
  139.  
  140.     $str .= getTendency($result_value);
  141.  
  142.     return $str;
  143.  
  144. }
  145.  
  146. function getSparklineViz($sql_object, $scale_id, $indicator, $threshold_value) {
  147.  
  148.     // getting all values
  149.     $req_sdiav=SQL_getAllValue("SCA", $scale_id, $indicator['sdii_id']);
  150.     $result_value = $sql_object -> DBSelect($req_sdiav);
  151.  
  152.     $str = '<div class="dashboard-indicator-sparkline">';
  153.     
  154.     // there is no value
  155.     if ($result_value==false) {
  156.         $str .= '<span class="infobox no-value">-</span>';
  157.  
  158.         // some values are there
  159.     } else {
  160.         $data = array();
  161.         // we reverse the array to display eldest first
  162.         $values = array_reverse($result_value);
  163.         
  164.         foreach($values as $value) {
  165.             array_push($data, $value['sdiv_value']);
  166.         }
  167.         $str .= '<p><span class="inlinebar">'.join(',',$data).'</span></p>';
  168.     }
  169.  
  170.     $str .= '</div>';
  171.  
  172.     
  173.     
  174.     $str .= getTendency($result_value);
  175.  
  176.     return $str;
  177.  
  178. }
  179.  
  180. function getViz($sql_object, $scale_id, $indicator, $threshold_value, $overwrite = null, $cursorcssposition = 0) {
  181.  
  182.     if(!is_null($overwrite)) {
  183.         $vizualisation_type = $overwrite;
  184.     } else {
  185.         $vizualisation_type = $indicator['sdii_dashboard_viz'];
  186.     }
  187.  
  188.     if($vizualisation_type == 'raw') {
  189.         $viz = getRawViz($sql_object, $scale_id, $indicator, $threshold_value);
  190.     }
  191.     if($vizualisation_type == 'gauge') {
  192.         $viz = getGaugeViz($sql_object, $scale_id, $indicator, $threshold_value, $cursorcssposition);
  193.     }
  194.     if($vizualisation_type == 'sparkline') {
  195.         $viz = getSparklineViz($sql_object, $scale_id, $indicator, $threshold_value, $cursorcssposition);
  196.     }
  197.  
  198.     return $viz;
  199. }
  200.  
  201. /**
  202.  * getTendency()
  203.  * Return indicator tendency based on value
  204.  * (not based on performance)
  205.  * @param array $values 
  206.  */
  207. function getTendency($values) {
  208.  
  209.     $tendency = '<div class="dashboard-indicator-tendency">';
  210.     // if there is a previous value
  211.     if (isset($values[1]['sdiv_value'])) {
  212.         $percentage = ($values[0]['sdiv_value'] - $values[1]['sdiv_value']) / $values[1]['sdiv_value'] * 100;
  213.         $evolution = ' ('.round($percentage, 0). '%)';
  214.         if ($values[0]['sdiv_value'] >= $values[1]['sdiv_value']) {
  215.             $tendency.="<img src=\"" .THEME_ADMIN_PATH. "images/ico_asc.gif\" alt=\""._t('dashboard','value_tendance')."\" title=\"".sprintf(_t('dashboard','previous_value'), $values[1]['sdiv_value']).$evolution."\" />";
  216.         } else {
  217.             $tendency.="<img src=\"" .THEME_ADMIN_PATH. "images/ico_desc.gif\" alt=\""._t('dashboard','value_tendance')."\" title=\"".sprintf(_t('dashboard','previous_value'), $values[1]['sdiv_value']).$evolution."\" />";
  218.         }
  219.     }
  220.     $tendency .= '</div>';
  221.     return $tendency;
  222. }

Documentation generated on Thu, 20 Mar 2014 16:47:14 +0100 by phpDocumentor 1.4.1