[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [9934]
From: |
Torstein |
Subject: |
[Fmsystem-commits] [9934] |
Date: |
Thu, 30 Aug 2012 08:57:28 +0000 |
Revision: 9934
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9934
Author: vator
Date: 2012-08-30 08:57:27 +0000 (Thu, 30 Aug 2012)
Log Message:
-----------
Modified Paths:
--------------
trunk/controller/inc/hook_home.inc.php
Modified: trunk/controller/inc/hook_home.inc.php
===================================================================
--- trunk/controller/inc/hook_home.inc.php 2012-08-30 08:14:09 UTC (rev
9933)
+++ trunk/controller/inc/hook_home.inc.php 2012-08-30 08:57:27 UTC (rev
9934)
@@ -34,7 +34,7 @@
include_class('controller', 'date_generator', 'inc/component/');
include_class('controller', 'location_finder', 'inc/helper/');
- $so = CreateObject('controller.socheck_list');
+ $so_check_list = CreateObject('controller.socheck_list');
$so_control = CreateObject('controller.socontrol');
$config = CreateObject('phpgwapi.config','controller');
@@ -43,18 +43,20 @@
$limit_no_of_assigned =
isset($GLOBALS['phpgw_info']['user']['preferences']['controller']['no_of_assigned_controls'])?
$GLOBALS['phpgw_info']['user']['preferences']['controller']['no_of_assigned_controls']
: (isset($config->config_data['no_of_assigned_controls']) &&
$config->config_data['no_of_assigned_controls'] > 0 ?
$config->config_data['no_of_assigned_controls']:10);
$dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
- $year = phpgw::get_var('year');
- if(empty($year)){
- $year = date("Y");
- }
+ $styling = "\n".'<!-- BEGIN checklist info -->'."\n ";
+ $styling .= "<style> .home_portal_content
a{color:#0066CC;text-decoration: none;text-transform: uppercase;}
.home_portal{margin: 20px 10px 0;} ";
+ $styling .= " .home-box {background: none repeat scroll 0 0 #EDF5FF;
border-color: #DBE5EF; border-radius: 4px; margin: 20px;}";
+ $styling .= " .home-box .home_portal{margin: 0;border: 1px solid
#DEEAF8;} .home_portal_content{padding:10px;} ";
+ $styling .= " .home_portal_title h2{ background: #DEEAF8; margin: 0;
padding: 5px 10px;} .home_portal_content ul li{padding: 7px 0;}";
+ $styling .= " .home_portal_content
.title{display:inline-block;width:300px;margin:0 20px 0 0;}
.home_portal_content .control-area{display:inline-block;width:200px;}";
+ $styling .= " .home_portal_content
.control{display:inline-block;width:300px;} .home_portal_content
.date{display:inline-block;width:300px;}";
+ $styling .= " .home_portal_content a span{cursor:
pointer;vertical-align: middle;}";
+ $styling .= "</style>";
+ $styling .= "\n".'<!-- END checklist info -->'."\n";
- $year = intval($year);
-
- $from_date_ts = strtotime("now");
- $to_year = $year + 1;
- $to_date_ts = strtotime("01/01/$to_year");
-
+ echo $styling;
+
// Fetches my properties
$criteria = array
(
@@ -81,16 +83,19 @@
$my_locations = array_merge($my_properties, $my_buildings);
-
- /* ======================================= CONTROLS NOT DONE
================================= */
+
+
+ /* ======================================= UNDONE ASSIGNED CONTROLS
FOR CURRENT USER ================================= */
+
$my_controls = array();
-
- $to_date_ts = strtotime("now");
- $to_year = date("Y") - 1;
- $from_date_ts = strtotime("01/01/$to_year");
$repeat_type = null;
+ // Setting from date 6 months back in time
+ $from_date_ts = mktime(0, 0, 0, date("n")-6, date("j"), date("Y") );
+ $to_date_ts = mktime(0, 0, 0, date("n"), date("j"), date("Y") );
+
+ // Fetches controls current user is responsible for
$my_controls = array();
foreach($my_locations as $location)
{
@@ -122,38 +127,38 @@
{
foreach($components_with_controls_array as $component)
{
- $my_controls[] = array( $location_code, 'component',
$component['controls_array'], $component );
+ $my_controls[] = array( $location_code, 'component',
$component['controls_array'], $component );
}
}
}
$my_undone_controls = array();
- $so_check_list = CreateObject('controller.socheck_list');
-
+
+ // Generates an array with undone controls
foreach($my_controls as $container_arr)
{
$location_code = $container_arr[0];
$control_type = $container_arr[1];
$controls = $container_arr[2];
-
+
foreach($controls as $my_control)
{
- if($my_control["repeat_type"] == 0)
+ if($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_DAY)
{
// Daily control: Fetch undone controls one
week back in time
$from_date_ts = mktime(0, 0, 0, date("n"),
date("j")-7, date("Y") );
}
- else if($my_control["repeat_type"] == 1)
+ else if($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_WEEK)
{
// Weekly control: Fetch undone controls one
month back in time
$from_date_ts = mktime(0, 0, 0, date("n")-1,
date("j"), date("Y") );
}
- else if($my_control["repeat_type"] == 2)
+ else if($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_MONTH)
{
// Monthly control: Fetch undone controls three
months back in time
$from_date_ts = mktime(0, 0, 0, date("n")-3,
date("j"), date("Y") );
}
- else if($my_control["repeat_type"] == 3)
+ else if($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_YEAR)
{
// Yearly control: Fetch undone controls one
year back in time
$from_date_ts = mktime(0, 0, 0, date("n"),
date("j"), date("Y")-1 );
@@ -208,25 +213,10 @@
'outerborderwidth' => '0',
'header_background_image' =>
$GLOBALS['phpgw']->common->image('phpgwapi','bg_filler', '.png', False)
));
-
- $app_id = $GLOBALS['phpgw']->applications->name2id('controller');
- if( !isset($GLOBALS['portal_order']) ||!in_array($app_id,
$GLOBALS['portal_order']) )
- {
- $GLOBALS['portal_order'][] = $app_id;
- }
-
- function cmp($a, $b)
- {
- if ($a[1] == $b[1]) {
- return 0;
- }
-
- return ($a[1] < $b[1]) ? -1 : 1;
- }
+ // Sorts my_undone_controls by deadline date
+ usort($my_undone_controls, "sort_cmp");
- usort($my_undone_controls, "cmp");
-
foreach($my_undone_controls as $my_undone_control)
{
@@ -291,21 +281,14 @@
}
}
- $styling = "\n".'<!-- BEGIN checklist info -->'."\n ";
- $styling .= "<style> .home_portal_content
a{color:#0066CC;text-decoration: none;text-transform: uppercase;}
.home_portal{margin: 20px 10px 0;} ";
- $styling .= " .home-box {background: none repeat scroll 0 0 #EDF5FF;
border-color: #DBE5EF; border-radius: 4px; margin: 20px;}";
- $styling .= " .home-box .home_portal{margin: 0;border: 1px solid
#DEEAF8;} .home_portal_content{padding:10px;} ";
- $styling .= " .home_portal_title h2{ background: #DEEAF8; margin: 0;
padding: 5px 10px;} .home_portal_content ul li{padding: 7px 0;}";
- $styling .= " .home_portal_content
.title{display:inline-block;width:300px;margin:0 20px 0 0;}
.home_portal_content .control-area{display:inline-block;width:200px;}";
- $styling .= " .home_portal_content
.control{display:inline-block;width:300px;} .home_portal_content
.date{display:inline-block;width:300px;}";
- $styling .= " .home_portal_content a span{cursor:
pointer;vertical-align: middle;}";
- $styling .= "</style>";
- $styling .= "\n".'<!-- END checklist info -->'."\n";
-
- echo $styling;
echo "\n".'<!-- BEGIN checklist info -->'."\n <div
class='home-box'>".$portalbox0->draw()."</div>\n".'<!-- END checklist info
-->'."\n";
+
- /* ======================================= MY PLANNED CONTROLS
================================= */
+
+
+
+
+ /* ======================================= PLANNED CONTROLS FOR
CURRENT USER ================================= */
$repeat_type = null;
$controls_for_location_array = array();
@@ -340,8 +323,6 @@
}
}
-
-
$portalbox1 = CreateObject('phpgwapi.listbox', array
(
'title' => "Mine planlagte kontroller",
@@ -353,22 +334,6 @@
'header_background_image' =>
$GLOBALS['phpgw']->common->image('phpgwapi','bg_filler', '.png', False)
));
- $app_id = $GLOBALS['phpgw']->applications->name2id('controller');
- if( !isset($GLOBALS['portal_order']) ||!in_array($app_id,
$GLOBALS['portal_order']) )
- {
- $GLOBALS['portal_order'][] = $app_id;
- }
- $var = array
- (
- 'up' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'down' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'close' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'question' => array('url' => '/set_box.php', 'app'
=> $app_id),
- 'edit' => array('url' => '/set_box.php', 'app' =>
$app_id)
- );
-
- /* ======================================= MY CONTROLS
================================= */
-
$category_name = array(); // caching
$cats = CreateObject('phpgwapi.categories', -1, 'controller',
'.control');
@@ -381,7 +346,7 @@
{
$curr_location = $control_instance[0];
$current_control = $control_instance[1];
- $check_lists =
$so->get_planned_check_lists_for_control($current_control["id"],
$curr_location, $current_control['location_id'],
$current_control['component_id']);
+ $check_lists =
$so_check_list->get_planned_check_lists_for_control($current_control["id"],
$curr_location, $current_control['location_id'],
$current_control['component_id']);
$location_array = execMethod('property.bolocation.read_single',
array('location_code' => $curr_location));
$location_name = $location_array["loc1_name"];
if(isset($current_control['component_id']) &&
$current_control['component_id'])
@@ -424,6 +389,11 @@
}
echo "\n".'<!-- BEGIN checklist info -->'."\n<div
class='home-box'>".$portalbox1->draw()."</div>\n".'<!-- END checklist info
-->'."\n";
+
+
+
+ /* ================================ CONTROLS ASSIGNED TO CURRENT USER
================================= */
+
$portalbox2 = CreateObject('phpgwapi.listbox', array
(
'title' => "Mine tildelte kontroller",
@@ -434,126 +404,196 @@
'outerborderwidth' => '0',
'header_background_image' =>
$GLOBALS['phpgw']->common->image('phpgwapi','bg_filler', '.png', False)
));
+
+
+ $my_controls = array();
+ $repeat_type = null;
+
+ $from_date_ts = strtotime("now");
+ $to_date_ts = mktime(0, 0, 0, date("n")+1, date("j"), date("Y") );
+
+ // Fetches controls current user is responsible for
+ $my_controls = array();
+ foreach($my_locations as $location)
+ {
+ $controls = array();
+ $components_with_controls_array = array();
+ $location_code = $location["location_code"];
+
+ $controls_loc = $so_control->get_controls_by_location(
$location_code, $from_date_ts, $to_date_ts, $repeat_type, "return_array",
$location["role_id"] );
+
+ $level = count(explode('-', $location_code));
- $app_id = $GLOBALS['phpgw']->applications->name2id('controller');
- if( !isset($GLOBALS['portal_order']) ||!in_array($app_id,
$GLOBALS['portal_order']) )
- {
- $GLOBALS['portal_order'][] = $app_id;
+ if($level == 1){
+ // Fetches all controls for the components for
a location within time period
+ $filter = "bim_item.location_code =
'$location_code' ";
+ $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
+ }else
+ {
+ // Fetches all controls for the components for
a location within time period
+ $filter = "bim_item.location_code LIKE
'$location_code%' ";
+ $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
+ }
+
+ if( count($controls_loc) > 0 )
+ {
+ $my_controls[] = array( $location_code, 'location',
$controls_loc );
+ }
+
+ if( count($components_with_controls_array) > 0 )
+ {
+ foreach($components_with_controls_array as $component)
+ {
+ $my_controls[] = array( $location_code, 'component',
$component['controls_array'], $component );
+ }
+ }
}
- $var = array
- (
- 'up' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'down' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'close' => array('url' => '/set_box.php', 'app' =>
$app_id),
- 'question' => array('url' => '/set_box.php', 'app'
=> $app_id),
- 'edit' => array('url' => '/set_box.php', 'app' =>
$app_id)
- );
+
+ $my_undone_controls = array();
- $category_name = array(); // caching
-
- $portalbox2->data = array();
- $portalbox2_data = array();
- foreach ($controls_array as $control_instance)
- {
- $curr_location = $control_instance[0];
- $current_control = $control_instance[1];
- //unset($check_lists);
- $check_lists =
$so->get_unplanned_check_lists_for_control($current_control["id"],
$curr_location);
- //$control_location =
$so_control->getLocationCodeFromControl($current_control->get_id());
- $location_array = execMethod('property.bolocation.read_single',
array('location_code' => $curr_location));
- $location_name = $location_array["loc1_name"];
- if(isset($current_control['component_id']) &&
$current_control['component_id'])
+ $from_date_ts = mktime(0, 0, 0, date("n"), date("j"), date("Y") );
+
+ // Generates an array with undone controls
+ foreach($my_controls as $container_arr)
+ {
+ $location_code = $container_arr[0];
+ $control_type = $container_arr[1];
+ $controls = $container_arr[2];
+
+ foreach($controls as $my_control)
{
- if($short_desc =
execMethod('property.soentity.get_short_description', array('location_id' =>
$current_control['location_id'], 'id' => $current_control['component_id'])))
+ if($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_DAY)
{
- $location_name .= "::{$short_desc}";
+ // Daily control: Todate in one week
+ $to_date_ts = mktime(0, 0, 0, date("n"),
date("j")+7, date("Y") );
}
+ else if(($my_control["repeat_type"] ==
controller_control::REPEAT_TYPE_WEEK)
+ | ($my_control["repeat_type"]
== controller_control::REPEAT_TYPE_MONTH)
+ | ($my_control["repeat_type"]
== controller_control::REPEAT_TYPE_YEAR))
+ {
+ // Daily, monthly yearly control: Todate in one
month
+ $to_date_ts = mktime(0, 0, 0, date("n")+1,
date("j"), date("Y") );
+ }
+
+ $date_generator = new
date_generator($my_control["start_date"], $my_control["end_date"],
$from_date_ts, $to_date_ts, $my_control["repeat_type"],
$my_control["repeat_interval"]);
+ $deadline_dates_for_control =
$date_generator->get_dates();
+
+ $check_list_array = array();
+ foreach($deadline_dates_for_control as $deadline_ts)
+ {
+ $check_list = null;
+
+ if($control_type == "location")
+ {
+ $check_list =
$so_check_list->get_check_list_for_control_by_date($my_control['id'],
$deadline_ts, null, $location_code, null, null, "location" );
+ }
+ else if($control_type == "component")
+ {
+ $component = $container_arr[3];
+
+ $check_list =
$so_check_list->get_check_list_for_control_by_date($my_control['id'],
$deadline_ts, null, null, $component['location_id'], $component['id'],
"component" );
+ }
+
+ if($check_list == null)
+ {
+ if($control_type == "location")
+ {
+ $my_undone_controls[] = array("add",
$deadline_ts, $my_control, "location", $location_code );
+ }
+ else if($control_type == "component")
+ {
+ $component = $container_arr[3];
+ $my_undone_controls[] = array("add",
$deadline_ts, $my_control, "component", $component['location_id'],
$component['id'] );
+ }
+ }
+ else if($check_list->get_status() ==
controller_check_list::STATUS_NOT_DONE)
+ {
+ $my_undone_controls[] = array("edit",
$deadline_ts, $my_control, $check_list->get_id(), $location_code );
+ }
+ }
}
-
+ }
+
+ // Sorts my_undone_controls by deadline date
+ usort($my_undone_controls, "sort_cmp");
+
+ foreach($my_undone_controls as $my_undone_control)
+ {
+ $check_list_status = $my_undone_control[0];
+ $deadline_ts = $my_undone_control[1];
+ $my_control = $my_undone_control[2];
+
+ $cats = CreateObject('phpgwapi.categories', -1, 'controller',
'.control');
+ $cats->supress_info = true;
+ $control_areas =
$cats->formatted_xslt_list(array('format'=>'filter','selected' => '','globals'
=> true,'use_acl' => $this->_category_acl));
+
foreach($control_areas['cat_list'] as $area)
{
- if($area['cat_id'] ==
$current_control["control_area_id"])
+ if($area['cat_id'] == $my_control["control_area_id"])
{
$control_area_name = $area['name'];
}
}
-
- $current_dates = $control_instance[2];
- foreach($current_dates as $current_date)
+ $date_str = date($dateformat, $deadline_ts);
+
+ if($check_list_status == "add")
{
- if(isset($check_lists))
+ $check_list_type = $my_undone_control[3];
+
+ if($check_list_type == "location")
{
- foreach($check_lists as $check_list)
- {
- if($current_date >
$check_list->get_deadline() && $current_date != $check_list->get_deadline())
- {
- $next_date = "Fristdato: " .
date($dateformat, $current_date);
- $portalbox2_data[] = array
- ($current_date, array
- (
- 'text' => "<span
class='title'>{$location_name}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$current_control["title"]}</span> <span
class='date'>{$next_date}</span>",
- 'link' =>
$GLOBALS['phpgw']->link('/index.php', array
- (
- 'menuaction'
=> 'controller.uicheck_list.add_check_list',
- 'deadline_ts'
=> $current_date,
- 'control_id'
=> $current_control["id"],
- 'location_code'
=> $curr_location,
- 'type'
=> $current_control['component_id'] ? 'component' : 'location',
- 'location_id'
=> $current_control['location_id'],
- 'component_id'
=> $current_control['component_id']
- ))
- ));
- }
- else
- {
- if(!$check_list->get_planned_date())
- {
- $next_date = "Fristdato: " .
date($dateformat, $check_list->get_deadline());
- $portalbox2_data[] = array
- ($check_list->get_deadline(),
array
- (
- 'text' => "<span
class='title'>{$location_name}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$current_control["title"]}</span> <span
class='date'>{$next_date}</span>",
- 'link' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uicheck_list.edit_check_list', 'check_list_id' =>
$check_list->get_id()))
- ));
- }
- }
- }
+ $location_code = $my_undone_control[4];
+ $location_array =
execMethod('property.bolocation.read_single', array('location_code' =>
$location_code));
+ $location_name = $location_array["loc1_name"];
+
+ $portalbox2->data[] = array(
+ 'text' => "<span
class='title'>{$location_name}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$my_control['title']}</span> <span class='date'>Fristdato
{$date_str}</span>",
+ 'link' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction' => 'controller.uicheck_list.add_check_list', 'type' =>
"location", 'control_id' => $my_control['id'], 'location_code' =>
$location_code, 'deadline_ts' => $deadline_ts))
+ );
}
- else
+ else if($check_list_type == "component")
{
- $next_date = "Fristdato: " . date($dateformat,
$current_date);
-
- $portalbox2_data[] = array
- ($current_date, array
- (
- 'text' => "<span
class='title'>{$location_name}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$current_control["title"]}</span> <span
class='date'>{$next_date}</span>",
- 'link' =>
$GLOBALS['phpgw']->link('/index.php', array
- (
- 'menuaction' =>
'controller.uicheck_list.add_check_list',
- 'deadline_ts' =>
$current_date,
- 'control_id' =>
$current_control["id"],
- 'location_code' =>
$curr_location,
- 'type' =>
$current_control['component_id'] ? 'component' : 'location',
- 'location_id' =>
$current_control['location_id'],
- 'component_id' =>
$current_control['component_id']
- ))
- ));
- }
+ $location_id = $my_undone_control[4];
+ $component_id = $my_undone_control[5];
+
+ $short_desc_arr =
execMethod('property.soentity.get_short_description', array('location_id' =>
$location_id, 'id' => $component_id));
+
+ $portalbox2->data[] = array(
+ 'text' => "<span
class='title'>{$short_desc_arr}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$my_control['title']}</span> <span class='date'>Fristdato
{$date_str}</span>",
+ 'link' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction' => 'controller.uicheck_list.add_check_list', 'type' =>
"component", 'control_id' => $my_control['id'], 'location_id' => $location_id,
'component_id' => $component_id, 'deadline_ts' => $deadline_ts))
+ );
+ }
}
- }
- //sort data by due date for check list
- sort($portalbox2_data);
- //$limit = 20;
- //$limit_no_of_assigned = 50;
- $tmp = 0;
- foreach($portalbox2_data as $check_list_dates)
- {
- if($tmp < $limit_no_of_assigned)
+ else if($check_list_status == "edit")
{
- $portalbox2->data[] = $check_list_dates[1];
+ $check_list_id = $my_undone_control[3];
+ $location_code = $my_undone_control[4];
+
+ $location_array =
execMethod('property.bolocation.read_single', array('location_code' =>
$location_code));
+ $location_name = $location_array["loc1_name"];
+
+ $portalbox0->data[] = array(
+ 'text' => "<span
class='title'>{$location_name}</span><span
class='control-area'>{$control_area_name}</span> <span
class='control'>{$my_control['title']}</span> <span class='date'>Fristdato
{$date_str}</span>",
+ 'link' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction' => 'controller.uicheck_list.edit_check_list',
'check_list_id' => $check_list_id))
+ );
}
- $tmp++;
}
- echo "\n".'<!-- BEGIN assigned checklist info -->'."\n<div
class='home-box'>".$portalbox2->draw()."</div>\n".'<!-- END assigned checklist
info -->'."\n";
+
+ echo "\n".'<!-- BEGIN checklist info -->'."\n <div
class='home-box'>".$portalbox2->draw()."</div>\n".'<!-- END checklist info
-->'."\n";
+
+
+
+ // ============================== FUNKSJONER
================================
+
+ // Sort array on timestamp
+ function sort_cmp($a, $b)
+ {
+ if ($a[1] == $b[1]) {
+ return 0;
+ }
+
+ return ($a[1] < $b[1]) ? -1 : 1;
+ }
+
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [9934],
Torstein <=