* @version $Id$
* @access public
* @license http://opensource.org/licenses/gpl-3.0.html
*/
include_once (override('../project/' . SQL . '.inc.php'));
include_once (override('../project/common.php'));
/**
* generate_html_recursive_with_progression()
*
* @see : http://stackoverflow.com/questions/7577396/php-walking-and-print-multi-dimensional-array
* @param unknown $data
* @return string
*/
/**
*
* @param array $data
* @param unknown $statut
* @param unknown $filter
* @param unknown $id_filter
* @param unknown $depth
* @param unknown $display_first
* @return string
*/
if (! function_exists('generate_html_recursive_with_progression')) {
function generate_html_recursive_with_progression($data, $statut, $filter, $id_filter, $depth, $workshop_id = -1)
{
// begin with an empty html string
$html = '';
// loop through all items in this level
foreach ($data as $key => &$item) {
// echo "$key
";
// where only interested in numeric items
// as those are the actual children
if (! is_numeric($key)) {
// otherwise continue
continue;
}
// 'level_parent' attribute is not set when there is no children level
if (isset($item['level_parent'])) {
// we display link only on main levels
$link_level = array(
'rub' => $GLOBALS['links'][U_L]['project']['linkvalue'],
'filter' => $GLOBALS['filters'][U_L]['level']['linkvalue'],
'id' => $item['level_id'],
'name' => $item['level_name']
);
if ($item['level_parent'] == 0) {
// $html .= '
";
// print_r($data[$j]);
// echo " ";
// we pass the level ID to the SQL query
// Dirty but it works .....
// PRIORITY and SCALE filters are handle later when choosing to displaying or not the project
// See on the '$projects' loop
if ($filter == 'TAG') {
$projects = $GLOBALS['sql_object']->DBSelect(SQL_getProjectsList(0, 999, $statut, 'LEVEL_TAG', $item['level_id'], $id_filter, $workshop_id));
} else {
$projects = $GLOBALS['sql_object']->DBSelect(SQL_getProjectsList(0, 999, $statut, 'LEVEL', $item['level_id'], $workshop_id));
}
// // we sort values on level names
// // Obtain a list of columns
// foreach ($projects as $key => $row) {
// $level[$key] = $row['level_name'];
// }
// // Sort the data with level descending
// // Add $projects as the last parameter, to sort by the common key
// array_multisort($level, SORT_DESC, $projects);
if ($projects != 0) {
$current_link = array(
'rub' => $GLOBALS['links'][U_L]['project']['linkvalue']
);
$current_level = '';
$html .= '
' . PHP_EOL; // ferme grid-6-small-3
} // boucle projet
} // test si projet
// $html .= '
' . PHP_EOL;
// call this funcion recursively
// with the next level ($item)
// it will figure out again whether that level has numeric children as well
// returns a new complete set, if applicable, otherwise an empty string
if (isset($item['children']))
$html .= generate_html_recursive_with_progression($item['children'], $statut, $filter, $id_filter, $depth + 1);
$html .= '
'; // on ferme le container des niveaux
}
// return the resulting html
return $html;
}
}
/**
* DisplayListProjectByLevelsWithProgression()
* Affichage de la liste des projets publics par niveaux
*
* @param string $statut
* @param integer $filter
* @param string $id_filter
* @param integer $debut
* @return string $content
*/
if (! function_exists('DisplayListProjectByLevelsWithProgression')) {
function DisplayListProjectByLevelsWithProgression($statut, $filter, $id_filter)
{
echo "";
$data = $GLOBALS['sql_object']->DBSelect(SQL_getLevelsList());
// we retrieve main levels
if ($filter != 'LEVEL') {
$data = getLevelChildren($data, 0); // 0 is parentid
$sublevels = $id_filter;
$depth = 0;
$comp = $GLOBALS['sql_object']->DBSelect(SQL_getTotalProjectCompletion('public'));
if (isset($comp) && is_array($comp))
$content = sprintf('
' . _t('project', 'completion-percentage') . '
', '' . round($comp[0]['completion'], 0) . '');
} else {
$current = $GLOBALS['sql_object']->DBSelect(SQL_getoneLevel($id_filter));
$data = getLevelChildren($GLOBALS['sql_object']->DBSelect(SQL_getLevelsList()), $id_filter);
$sublevels = array_extract($data, 'level_id', true, 'children');
// if there is no sub-menu, we are working on last levels
// we emulate a level by passing choosen level but 'level_parent' is not set
if (count($sublevels) == 0) {
$sublevels = array(
$id_filter
);
$data = $current;
}
$content = '
';
// Animate progression bar
if (defined('ANIMATE_PROGRESS') && ANIMATE_PROGRESS == 1) {
footerAddJS('../lib/js/waypoints/lib/jquery.waypoints.min.js');
echo "";
}
}
}
/**
* generate_html_recursive()
*
* @see : http://stackoverflow.com/questions/7577396/php-walking-and-print-multi-dimensional-array
* @param unknown $data
* @return string
*/
/**
*
* @param array $data
* @param unknown $statut
* @param unknown $filter
* @param unknown $id_filter
* @param unknown $depth
* @param unknown $display_first
* @return string
*/
if (! function_exists('generate_html_recursive')) {
function generate_html_recursive($data, $statut, $filter, $id_filter, $depth, $workshop_id = -1)
{
// begin with an empty html string
$html = '';
// loop through all items in this level
foreach ($data as $key => &$item) {
// echo "$key
";
// where only interested in numeric items
// as those are the actual children
if (! is_numeric($key)) {
// otherwise continue
continue;
}
// 'level_parent' attribute is not set when there is no children level
if (isset($item['level_parent'])) {
// we display link only on main levels
$link_level = array(
'rub' => $GLOBALS['links'][U_L]['project']['linkvalue'],
'filter' => $GLOBALS['filters'][U_L]['level']['linkvalue'],
'id' => $item['level_id'],
'name' => $item['level_name']
);
if ($item['level_parent'] == 0) {
$html .= '
";
// print_r($data[$j]);
// echo " ";
// we pass the level ID to the SQL query
// Dirty but it works .....
// PRIORITY and SCALE filters are handle later when choosing to displaying or not the project
// See on the '$projects' loop
if ($filter == 'TAG') {
$projects = $GLOBALS['sql_object']->DBSelect(SQL_getProjectsList(0, 999, $statut, 'LEVEL_TAG', $item['level_id'], $id_filter, $workshop_id));
} else {
$projects = $GLOBALS['sql_object']->DBSelect(SQL_getProjectsList(0, 999, $statut, 'LEVEL', $item['level_id'], $workshop_id));
}
// // we sort values on level names
// // Obtain a list of columns
// foreach ($projects as $key => $row) {
// $level[$key] = $row['level_name'];
// }
// // Sort the data with level descending
// // Add $projects as the last parameter, to sort by the common key
// array_multisort($level, SORT_DESC, $projects);
if ($projects != 0) {
$current_link = array(
'rub' => $GLOBALS['links'][U_L]['project']['linkvalue']
);
$current_level = '';
$html .= '
' . PHP_EOL;
}
// call this funcion recursively
// with the next level ($item)
// it will figure out again whether that level has numeric children as well
// returns a new complete set, if applicable, otherwise an empty string
if (isset($item['children']))
$html .= generate_html_recursive($item['children'], $statut, $filter, $id_filter, $depth + 1);
}
// return the resulting html
return $html;
}
}
/**
* DisplayListProjectByLevels()
* Affichage de la liste des projets publics par niveaux
*
* @param string $statut
* @param integer $filter
* @param string $id_filter
* @param integer $debut
* @return string $content
*/
if (! function_exists('DisplayListProjectByLevels')) {
function DisplayListProjectByLevels($statut, $filter, $id_filter)
{
$data = $GLOBALS['sql_object']->DBSelect(SQL_getLevelsList());
// we retrieve main levels
if ($filter != 'LEVEL') {
$data = getLevelChildren($data, 0); // 0 is parentid
$sublevels = $id_filter;
$depth = 0;
$comp = $GLOBALS['sql_object']->DBSelect(SQL_getTotalProjectCompletion('public'));
if (isset($comp) && is_array($comp))
$content = sprintf('
' . _t('project', 'completion-percentage') . '
', '' . round($comp[0]['completion'], 0) . '');
} else {
$current = $GLOBALS['sql_object']->DBSelect(SQL_getoneLevel($id_filter));
$data = getLevelChildren($GLOBALS['sql_object']->DBSelect(SQL_getLevelsList()), $id_filter);
$sublevels = array_extract($data, 'level_id', true, 'children');
// if there is no sub-menu, we are working on last levels
// we emulate a level by passing choosen level but 'level_parent' is not set
if (count($sublevels) == 0) {
$sublevels = array(
$id_filter
);
$data = $current;
}
$content = '
';
}
}
/**
* getProjectImpacts()
* Affichage des impacts d'un projet sous forme graphique
*
* @param string $impactsField
* @param string $title
* @return string
*/
if (! function_exists('getProjectImpacts')) {
function getProjectImpacts($impactsField, $title = true)
{
// if not defined or not enabled we return empty string
if (! defined('PROJECT_IMPACTS') || PROJECT_IMPACTS == 0)
return '';
$project_impacts = unserialize($impactsField);
// no values, we return empty string
if (! is_array($project_impacts))
return '';
$display_impacts = '';
foreach ($project_impacts as $k => $v) {
$display_impacts .= '
' . PHP_EOL;
}
return $content;
}
}
/**
* getFinalities()
*
* @param $id (optionnal)
* @param $mode (optionnal)
* : take value 'read' or 'write' or 'array'
* @param $selected (optionnal)
* : array with selected values - useful when adding / changing current values
* @return array
*/
if (! function_exists('getFinalities')) {
function getFinalities($id = false, $mode = 'read', $selected = array())
{
// we get all values
$init = $GLOBALS['sql_object']->DBSelect(SQL_getFinalities(false));
// we get finalities for the given project if needed
// and we merge all selected values in $selected array
if (is_numeric($id)) {
$data = $GLOBALS['sql_object']->DBSelect(SQL_getFinalities($id));
if (isset($data[0]['finality_id'])) {
foreach ($data as $item) {
if (! in_array($item['finality_id'], $selected))
array_push($selected, $item['finality_id']);
}
}
}
$content = '';
if (isset($init[0]['finality_id'])) {
$array = array();
if ($mode == 'read' || $mode == 'array') {
$content .= '
' . PHP_EOL;
}
return $content;
}
}
/**
* getAssociatedIndicatorsValues()
*
* @param integer $id
* @return string
*/
if (! function_exists('getAssociatedIndicatorsValues')) {
function getAssociatedIndicatorsValues($id, $orderedIndicators = null, $extraclass = '', $cursorcssposition = 0, $addvalues = false)
{
global $l21auth;
global $sql_object;
include_once ('../dashboard/display.php');
include_once ('../dashboard/mysql.inc.php');
$result_sdi = $GLOBALS['sql_object']->DBSelect(SQL_getProjectSdiValues($id));
$content = '';
$id_filter = 1; // scale id value
if (CURRENT_APP == 'admin' && ($l21auth->isProjectManager($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin())) {
$displayLink = true;
// we add script for sorting indicators
footerAddJS('../lib/js/jquery.tablednd.1.0.5.min.js');
dragTableSettings(array('id' => $id, 'order' => 'indic'));
} else {
$displayLink = false;
}
if (is_array($result_sdi) && $result_sdi[0] != 0) {
$ordered_indics = array();
// we prepare ordered data if given
// 1 - first data stored in $orderedIndicators, then all data
if(!is_null($orderedIndicators)) $tmp = unserialize($orderedIndicators);
if(isset($tmp) && is_array($tmp)) {
foreach($tmp as $k => $v) {
if(is_integer($k)) array_push($ordered_indics, $k); // to be sure it is not empty
}
}
// 2 - then, we iterate on all indicators thare are not already in $ordered_indics
foreach($result_sdi as $sdi) {
if($sdi['sdii_statut'] == 'P' && !in_array($sdi['sdii_id'], $ordered_indics)) array_push($ordered_indics, $sdi['sdii_id']); // to be sure it is not empty
}
$content .= '
' . PHP_EOL;
if ($displayLink === true)
$content .= '
' . mb_ucfirst(_t('divers', 'actions')) . '
' . PHP_EOL;
$content .= '
' . PHP_EOL;
$content .= '' . PHP_EOL;
$content .= '' . PHP_EOL;
foreach($ordered_indics as $k => $v) {
// we search for the key of searched element : $j
// then we display the full record
$j = array_search($v, array_column($result_sdi, 'sdii_id'));
// we display values only if indicator is public
if ($result_sdi[$j]['sdii_statut'] == 'P') {
// setting $threshold_value
// By default initial value
$threshold_value = $result_sdi[$j]['sdii_threshold_value'];
// if set, we get the latest for the given scale
$r = $GLOBALS['sql_object']->DBSelect(SQL_getlastInsertByPublicationDate($result_sdi[$j]['sdii_id'], 1));
if (isset($r[0]['sdiv_value']) && ! is_null($r[0]['sdiv_threshold'])) {
$threshold_value = $r[0]['sdiv_threshold'];
}
if ($displayLink === true) {
$link_add_values = './index.php?rub=dashboard&todo=add&id=' . $result_sdi[$j]['sdii_id'] . '&scale_id=' . $id_filter;
$addvalues_link = "