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.     $listing =    "<div class=\"dashboard-indicator-gauge indicator-info-container\">
  94.     <a href=\"index.php?rub=dashboard&amp;todo=det&amp;id=".$indicator['sdii_id']."&amp;scale_id=".$scale_id."\" class=\"infobox\">
  95.     <img src=\"" .THEME_ADMIN_PATH"images/".$gauge."\" alt=\"".ucfirst(_t('dashboard','value'))." : ".$current_value." (".formatText($indicator['sdii_unit']).") ".
  96.     "\n ".ucfirst(_t('sdi','min_value'))." : ".empty_nc($indicator['sdii_min_value']).
  97.     "\n ".ucfirst(_t('sdi','max_value'))." : ".empty_nc($indicator['sdii_max_value']).
  98.     "\n ".ucfirst(_t('sdi','threshold_value'))." : ".empty_nc($threshold_value)."\"  /></a>";
  99.     $listing .= getIndicatorInfoBox($current_value$indicator$threshold_value$class);
  100.     $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;\"/>";
  101.  
  102.  
  103.     $listing .= getTendency($result_value);
  104.  
  105.     $listing .= "\t<span class=\"value\"> (".strtolower($current_value).")</span>\n";
  106.     $listing .= "\t</div>\n";
  107.  
  108.     return     $listing;
  109. }
  110.  
  111. function getRawViz($sql_object$scale_id$indicator$threshold_value{
  112.  
  113.     $req_sdiav=SQL_getAllValue("SCA"$scale_id$indicator['sdii_id']);
  114.     $result_value $sql_object -> DBSelect($req_sdiav);
  115.  
  116.     $str '<div class="dashboard-indicator-raw">';
  117.  
  118.     // there is no value
  119.     if ($result_value==false{
  120.         $str .= '<span class="infobox no-value">-</span>';
  121.         $current_value _t('dashboard','novalue');
  122.         $class="indicator-no-data";
  123.         // some values are there
  124.     else {
  125.         $str .= '<span class="infobox value">'.$result_value[0]['sdiv_value'].'</span>';
  126.         $current_value $result_value[0]['sdiv_value'];
  127.         $class="";
  128.     }
  129.     $str .= getIndicatorInfoBox($current_value$indicator$threshold_value$class);
  130.  
  131.     $str .= '<span class="unit">'.formatText($indicator['sdii_unit']).'</span>';
  132.     $str .= '</div>';
  133.  
  134.     $str .= getTendency($result_value);
  135.  
  136.     return $str;
  137.  
  138. }
  139.  
  140. function getViz($sql_object$scale_id$indicator$threshold_value$overwrite null$cursorcssposition 0{
  141.  
  142.     if(!is_null($overwrite)) {
  143.         $vizualisation_type $overwrite;
  144.     else {
  145.         $vizualisation_type $indicator['sdii_dashboard_viz'];
  146.     }
  147.  
  148.     if($vizualisation_type == 'raw'{
  149.         $viz getRawViz($sql_object$scale_id$indicator$threshold_value);
  150.     }
  151.     if($vizualisation_type == 'gauge'{
  152.         $viz getGaugeViz($sql_object$scale_id$indicator$threshold_value$cursorcssposition);
  153.     }
  154.  
  155.     return $viz;
  156. }
  157.  
  158. /**
  159.  * getTendency()
  160.  * Return indicator tendency based on value
  161.  * (not based on performance)
  162.  * @param array $values 
  163.  */
  164. function getTendency($values{
  165.  
  166.     $tendency '<div class="dashboard-indicator-tendency">';
  167.     // if there is a previous value
  168.     if (isset($values[1]['sdiv_value'])) {
  169.         $percentage ($values[0]['sdiv_value'$values[1]['sdiv_value']$values[1]['sdiv_value'100;
  170.         $evolution ' ('.round($percentage0)'%)';
  171.         if ($values[0]['sdiv_value'>= $values[1]['sdiv_value']{
  172.             $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."\" />";
  173.         else {
  174.             $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."\" />";
  175.         }
  176.     }
  177.     $tendency .= '</div>';
  178.     return $tendency;
  179. }

Documentation generated on Mon, 08 Apr 2013 18:13:29 +0200 by phpDocumentor 1.4.1