* @version $Id$ * @access public * @license http://opensource.org/licenses/gpl-3.0.html */ /** * get_task_form() * * @param int $task_id * @return string */ if(!function_exists('get_task_form')) { function get_task_form($project_id, $task_id = false, $form_values = array(), $err_msg = false) { $a = []; $a['user_id'] = $GLOBALS['l21auth']->GetSessionElement('id'); $achieved = ''; $reminder_last_date = ''; // $project_id always exists even when Project does not exist yet in db // a tmp id is given when project does not exist yet. See add.php page $a['project_id'] = $project_id; // we get given task if provided and populate field if(is_numeric($task_id)) { $r = $GLOBALS['sql_object']->DBSelect(SQL_get_task($task_id)); // print_r($r); $formname = 'edit-task'; $title = _t('task','edit'); $a['todo'] = 'edit'; $a['id'] = $task_id; $a['label'] = $r[0]['task_label']; $a['status'] = $r[0]['task_status']; $a['reminder-f'] = $r[0]['task_reminder_freq']; $a['reminder-f-hidden'] = $r[0]['task_reminder_freq']; $a['reminder-last-date'] = $r[0]['task_reminder_lastdate']; if($r[0]['task_date_done'] != '0001-01-01 00:00:00') $achieved = '
'. mb_ucfirst(_t('task', 'achieved_at')). ' '. $r[0]['task_date_done_display']. ' (' ._t('task', 'duration'). ' : ' .$r[0]['duration'] . ' '._t('task', 'months').')'.''; if($r[0]['task_reminder_lastdate'] != '0001-01-01 00:00:00') $reminder_last_date = ''. sprintf(mb_ucfirst(_t('task', 'reminder_lastdate')), $r[0]['task_reminder_lastdate_display']).''; if($a['reminder-f'] != 'NO REMINDER' && $a['status'] != 'done') { $res = $GLOBALS['sql_object']->DBSelect(SQL_get_next_reminder_date($a['id'], $a['reminder-f'])); $reminder_last_date .= '('. sprintf(mb_ucfirst(_t('task', 'reminder_nextdate')), $res[0]['next_send']).')'; } } else { // we add a new record $formname = 'add-task'; $title = _t('task','add'); $a['todo'] = 'add'; $a['label']=""; $a['status'] = 'todo'; $a['reminder-f'] = 'NO REMINDER'; $a['reminder-f-hidden'] = $a['reminder-f']; } // form as been submited already, we populate it again with entered values if(!empty($form_values)) { $a['label'] = $form_values['label']; $a['status'] = $form_values['status']; $a['reminder-f'] = $form_values['reminder_freq']; $a['reminder-f-hidden'] = $form_values['reminder_freq_hidden']; } $otask = new projectTask(); $select_reminders = TasksReminderSelectBox($otask->available_frequencies, 'task-reminder-f', $a['reminder-f']); $radio_status = TasksReminderStatusRadio($otask->available_status, 'task-status', $a['status']); // echo $a['project_id']; $form = '

'.$title.'

'.PHP_EOL; if(is_string($err_msg)) $form .= '
' . $err_msg . '
'; $form .= '
'; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'._t('task', 'status').' : *
'.PHP_EOL; $form .= '
'.$radio_status . $achieved.'
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.$select_reminders. $reminder_last_date . ' '._t('task', 'reminder_freq_info').'
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= '
'.PHP_EOL; $form .= ''.PHP_EOL; if($a['todo'] == 'edit') $form .= ''.PHP_EOL; $form .= ''.PHP_EOL; $form .= ''.PHP_EOL; $form .= ''.PHP_EOL; $form .= ''.PHP_EOL; $form .= ''.PHP_EOL; $form .= '
'.PHP_EOL; $js = ''; $form .= $js . PHP_EOL; return $form; } } /** * get_task_progress_bar() * * @param integer $id * @return string */ if(!function_exists('get_task_progress_bar')) { function get_task_progress_bar($project_id, $report = false) { $r = $GLOBALS['sql_object']->DBSelect(SQL_get_project_tasks_count($project_id)); // we get all tasks if($r[0]['count'] == 0) return '
'; $d = $GLOBALS['sql_object']->DBSelect(SQL_get_project_tasks_count($project_id, array('done'))); // we get all done tasks if(!is_array($d)) $done = 0; else $done = $d[0]['count']; $value = round($done * 100 / $r[0]['count'], 0); $progresstext = sprintf(''._t('task', 'progression').'', $done, $r[0]['count'], $value); if($report) return strip_tags($progresstext); return sprintf('
%s
', $value, $project_id, $value, $progresstext); } } function get_task_status($status) { return $GLOBALS['lang']['task']['status_'.$status]; } /** * get_tasks_for_report() * * @param array $tasks * @return array */ if(!function_exists('get_tasks_for_report')) { function get_tasks_for_report($tasks = false) { $a = array(); if(!is_array($tasks)) return $a; foreach ($tasks as $task) { $t = array(); $t['status_raw'] = $task['task_status']; $t['status'] = get_task_status($task['task_status']); $t['label'] = formatText($task['task_label']); if($task['task_status'] == 'done') $t['done'] = mb_ucfirst(_t('task', 'achieved_at')). ' '. $task['task_date_done_display']. ' (' ._t('task', 'duration'). ' : ' .$task['duration'] . ' '._t('task', 'months').')'; array_push($a, $t); } return $a; } } /** * format_tasks() * * @param array $tasks * @return array */ if(!function_exists('format_tasks')) { function format_tasks($tasks = false, $edition = false) { $str =''; footerAddJS('../lib/js/jquery.nestable.js'); $js = '$("body").on("scroll", "div.dd", function(e) { // necessary to bind dynamically nestable $("div.dd").nestable({listNodeName: "ul"}).on("change", function() { var json_text = $("div.dd").nestable("serialize"); //console.log(json_text); $.get("../admin/_ajax_sort.php", { rub: "task", "sort-table": json_text }, function(data){ // console.log(data); // replacing data.class by data["class"] for IE8 bug fix if(data["class"] == "succeed") { alertify.success(data.msg); } else { alertify.error(data.msg); } }, "json"); }); }); $("div.dd").trigger("scroll"); // necessary to bind dynamically nestable'; footerAddInlineJS($js); // we need to include JQuery even if empty because some elements can be added later if($edition) { $js = ' // to bind dynamic elements $("body").on("click", "li.tasks a.edit-task", function(e) { e.preventDefault(); var cboxOptions = { href:$(this).attr("href"), iframe:true, innerWidth: "50%", innerHeight: "80%", maxWidth: "85%", maxHeight: "85%", onOpen: setColorBoxFlag("project-edit") } $(this).colorbox(cboxOptions); // a bit complicated to handle alertify.success() message. Handle by colorbox on closed .... Code is in mod.php / add.php pages }); $("body").on("click", "ul.project-tasks a.ico_sup", function(e) { $.ajax({ url : $(this).attr("href"), type: "GET", dataType: "json", success: function(data) { if(data.status==1) { $(data.el).fadeOut("slow"); $("#progressbar-project-container").replaceWith(data.htmlContent).hide().fadeOut(); alertify.success(data.msg); // if on sync we update completion indicator if($("#project_progression_sync").length > 0) { if($("#project_progression_sync").is(":checked")) { var curval = $("#progressbar-project-container").attr("data-tasks-percentage"); // var rounded = Math.ceil(curval / '. PROJECT_STEP .') * '.PROJECT_STEP . '; // console.log("Tasks SYNC / curval : " + curval + " - rounded : " + rounded); $("#project_progression").val(curval); displayValue(curval); } } } else { alertify.error(data.msg); } } }); return false; });'; footerAddInlineJS($js); } if(!is_array($tasks)) return sprintf('
    %s
', $str); // we return container for adding further task foreach ($tasks as $task) { $meta = mb_ucfirst(_t('divers', 'created_on')). ' '. $task['task_date_crea_display']. ' - ' .mb_ucfirst(_t('divers', 'last_modify')). ' '. $task['task_last_modify_display']. ' ' . _t('divers', 'by'). ' '. $task['user_login']; $str .= '
  • '.PHP_EOL; $str .= '
     
    '.PHP_EOL; $str .= '
    '.PHP_EOL; $str .= ''.get_task_status($task['task_status']).''.nl2br($task['task_label']); if($task['task_status'] == 'done') $str .= ''. mb_ucfirst(_t('task', 'achieved_at')). ' '. $task['task_date_done_display']. ' (' ._t('task', 'duration'). ' : ' .$task['duration'] . ' '._t('task', 'months').')'.''; if($edition) { $str .= ''; } $str .= '
    '.PHP_EOL; $str .= '
  • '; } return sprintf('
      %s
    ', $str); } } /** * get_finalities() * * @param $id (optionnal) : numeric / false * @param $as_string (optionnal) : true / false * @param $separator (optionnal) : default ',' * @return array */ if(!function_exists('get_finalities')) { function get_finalities($id = false, $as_string = true, $separator = ',') { // we get all values $init = $GLOBALS['sql_object']->DBSelect(SQL_getFinalities($id)); if (! isset ( $init [0] ['finality_id'] )) return false; $simple_array = array (); $array = array (); for($i = 0; $i < count ( $init ); $i ++) { $array [$i] ['finality_name'] = $init [$i] ['finality_name']; $array [$i] ['finality_id'] = $init [$i] ['finality_id']; array_push ( $simple_array, $init [$i] ['finality_name'] ); } if ($as_string) { return join ( $separator . ' ', $simple_array ); } else { return $array; } } } function get_sql_status($value) { $a = array('public' => 'P', 'draft' => 'A', 'archives_p' => 'PA', 'archives_a' => 'AA'); if(!key_exists($value, $a)) return false; else return $a[$value]; } /** * getInternalNav() * get internal navigation based on current view * @return string */ if(!function_exists('getInternalNav')) { function getInternalNav() { $dv_class = $fv_class = $fiv_class = ''; if(!isset($_REQUEST['view'])) $dv_class = 'active'; if(isset($_REQUEST['view']) && $_REQUEST['view'] == 'flat') $fv_class = 'active'; if(isset($_REQUEST['view']) && $_REQUEST['view'] == 'finality') $fiv_class = 'active'; $finality_view = $modify_link = ''; $default_view =''._t('project','level_view').''; $flat_view = ''._t('project','flat_view').''; if(defined('PROJECT_FINALITIES') && PROJECT_FINALITIES == 1) $finality_view =''._t('project','finality_view').''; if($GLOBALS['l21auth']->isSuperAdmin ()) $modify_link =''._t('project','modify_actors').''; $navbar = $default_view . $flat_view . $finality_view. $modify_link ; return sprintf('
    ', $navbar); } } if(!function_exists('getMenuFilter')) { /** * getMenuFilter() * * @param array $tags * @return string */ function getMenuFilter ($tags = array(), $finalities = array(), $scales = array(), $priorities = array()) { footerAddJS('../lib/js/jquery-tag-filtering/jquery.tagfiltering.simo.js'); addDynamicCSS('../lib/js/jquery-tag-filtering/jquery.tagfiltering.simo.css'); // one call to apply many filters from several lists (ul) with same css class and using distincts data-* attributes // to comment if individual filtering are applied footerAddInlineJS('$("ul.filter-menu").tagfiltering({target_attr:"data-priorities,data-tags,data-finalities,data-scales", separator:";", callback:compute_values});'); // export Javascript part $js = '$("#save-export").click( function() { var to_export = []; var $items = $(".filter-items").children(); // we populate the array to send with ajax $items.each(function() { if($(this).is(":visible")) { var curval = $(this).attr("data-id"); // we check if not in array yet - could happen when using "Finality view" if($.inArray( curval,to_export) == -1) to_export.push($(this).attr("data-id")); } }); alertify.success("'. _t('items', 'selected').'".replace("%s", to_export.length)); $.ajax({ type: "POST", data: {to_export:to_export}, url: "../project/_ajax_save.php?token='.SECRET_KEY.'", success: function(msg){ window.location = "../admin/index.php?rub=project&todo=report"; } }); });'; footerAddInlineJS($js); $filter_menu = ''; $filter_menu .= ''; return $filter_menu; } } if(!function_exists('getCompletionMenuFilter')) { /** * getCompletionMenuFilter() * * get completion menu filter * @param array $tags * @return string */ function getCompletionMenuFilter ($steps = PROJECT_STEP, $initialValue = 0) { // one call to apply many filters from several lists (ul) with same css class and using distincts data-* attributes // to comment if individual filtering are applied footerAddInlineJS(' $("#completion-operator").on("change", function() {$( "#completion-filter" ).trigger( "input" );}); $(document).on("input", "#completion-filter", function() { var current = $(this).val(); var operator = $("#completion-operator").find(":selected").val(); console.log(current); console.log(operator); if(operator == "all") { current = 0; operator = ">="; $("#completion-filter").val(current); } $("#completion-filter-value").text(current + " %").hide().fadeIn(); $("tbody.filter-items tr").show(); $("tbody.filter-items tr").filter(function() { if(operator == ">=") return parseInt($(this).attr("data-completion")) < parseInt(current-1); else if(operator == "<=") return parseInt($(this).attr("data-completion")) > parseInt(current); else return parseInt($(this).attr("data-completion")) != parseInt(current); // operator == "=" }) .hide(); // !!!! with fadeOut(), compute_values() does not update compute_values(); });'); $filter = ''; $options = ''; $options .= ''.$initialValue.' %'; $filter .= sprintf('

    %s

    %s
    ', _t('filter', 'by_completion'), $options); return $filter; } } if(!function_exists('getPriorityMenuFilter')) { /** * getScalesMenuFilter() * * get tags menu filter * @param array $tags * @return string */ function getPriorityMenuFilter ($priorities) { // to uncomment to apply filter only on scales (without finalities / tags considerations) //footerAddInlineJS('$("ul.priorities-filter-menu").tagfiltering({target_attr:"data-priority", exclude_parents:"ul.filter-menu", separator:";", callback:compute_values});'); $filter = ''; // we display filter if at least 2 values exists if(count($priorities) > 1) { $options = ''; $a = array(); foreach($priorities as $item) { if(!in_array($item['priority_id'], $a)) { $options .= '
  • '.$item['priority_name'].'
  • '; array_push($a, $item['priority_id']); } } $filter .= sprintf('

    %s

      %s
    ', _t('filter', 'by_priority'), $options); } return $filter; } } if(!function_exists('getScalesMenuFilter')) { /** * getScalesMenuFilter() * * get tags menu filter * @param array $tags * @return string */ function getScalesMenuFilter ($scales) { // to uncomment to apply filter only on scales (without finalities / tags considerations) //footerAddInlineJS('$("ul.scales-filter-menu").tagfiltering({target_attr:"data-scales", exclude_parents:"ul.filter-menu", separator:";", callback:compute_values});'); $filter = ''; // we display filter if at least 2 values exists if(count($scales) > 1) { $options = ''; $a = array(); foreach($scales as $item) { if(!in_array($item['scale_id'], $a)) { $options .= '
  • '.$item['scale_name'].'
  • '; array_push($a, $item['scale_id']); } } $filter .= sprintf('

    %s

      %s
    ', _t('filter', 'by_scale'), $options); } return $filter; } } if(!function_exists('getFinalitiesMenuFilter')) { /** * getTagsMenuFilter() * * get tags menu filter * @param array $tags * @return string */ function getFinalitiesMenuFilter ($finalities) { // to uncomment to apply filter only on finalities (without scales / tags considerations) //footerAddInlineJS('$("ul.finalities-filter-menu").tagfiltering({target_attr:"data-finalities", exclude_parents:"ul.filter-menu", separator:";", callback:compute_values});'); $filter = ''; if(defined('PROJECT_FINALITIES') && PROJECT_FINALITIES == 1) { // we display filter if at least 2 values exists if(count($finalities) > 1) { $options = ''; $a = array(); foreach($finalities as $item) { if(!in_array($item['finality_id'], $a)) { $options .= '
  • '.$item['finality_name'].'
  • '; array_push($a, $item['finality_id']); } } $filter .= sprintf('

    %s

      %s
    ', _t('filter', 'by_finality'), $options); } } return $filter; } } if(!function_exists('getTagsMenuFilter')) { /** * getTagsMenuFilter() * * get tags menu filter * @param array $tags * @return string */ function getTagsMenuFilter ($tags) { // to uncomment to apply filter only on tags (without scales / finalities considerations) //footerAddInlineJS('$("ul.tags-filter-menu").tagfiltering({target_attr:"data-tags", exclude_parents:"ul.filter-menu", separator:";", callback:compute_values});'); $filter = ''; // we display filter if at least 1 values exists if(count($tags) >= 1) { $options = ''; $a = array(); foreach($tags as $item) { if(!in_array($item['tag_id'], $a)) { $options .= '
  • '.$item['tag_name'].'
  • '; array_push($a, $item['tag_id']); } } $filter .= sprintf('

    %s

      %s
    ', _t('filter', 'by_tag'), $options); } return $filter; } }