home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / projects / load.inc < prev    next >
Encoding:
Text File  |  2004-03-08  |  13.6 KB  |  370 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. $show_period = isset($_GET['show_period']) ? $_GET['show_period'] : 'all';
  14. $load_user_id = isset($_GET['load_user_id']) ? $_GET['load_user_id'] : $GO_SECURITY->user_id;
  15. $load_type = isset($_GET['load_type']) ? $_GET['load_type'] : 'project';
  16. $print = (isset($_GET['print']) && $_GET['print'] == 'true') ? true : false;
  17. $project_id = isset($_GET['project_id']) ? $_GET['project_id'] : '0';
  18.  
  19.  
  20. $time = get_time();
  21. $this_day = date("j", $time);
  22. $this_year = date("Y", $time);
  23. $this_month = date("m", $time);
  24.  
  25. $month = isset($_GET['month']) ? $_GET['month'] : $this_month;
  26. $year = isset($_GET['year']) ? $_GET['year'] : $this_year;
  27.  
  28. $module_url = isset($projects_module) ? $projects_module['url'] : $GO_MODULES->url;
  29.  
  30. if (isset($_REQUEST['delete_hours']))
  31. {
  32.     if ($working_hours = $projects->get_working_hours($_REQUEST['delete_hours']))
  33.     {
  34.         if($_project = $projects->get_project($working_hours['project_id']))
  35.         {
  36.             if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $_project['acl_write']))
  37.             {
  38.                 $projects->delete_hours($_REQUEST['delete_hours']);
  39.             }else
  40.             {
  41.                 echo '<p class="Error">'.$strAccessDenied.'</p>';
  42.             }
  43.         }
  44.     }
  45. }
  46.  
  47.  
  48. if (!$print)
  49. {
  50.     echo '<h3>'.$pm_load_type.':</h3>';
  51.     echo '<table border="0" cellspacing="0" cellpadding="4">';
  52.  
  53.     if (!isset($fixed_project_id) && $contacts_module = $GO_MODULES->get_module('addressbook'))
  54.     {
  55.         if($has_contacts_module = ($contacts_module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_write']))))
  56.         {
  57.             $contact_name = isset($_GET['contact_name']) ? $_GET['contact_name'] : '';
  58.             $load_contact_id = isset($_GET['load_contact_id']) ? $_GET['load_contact_id'] : '0';
  59.             echo '<tr><td><table border="0" cellpadding="0" cellspacing="0"><tr><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?show_contacts=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id\',\'550\',\'400\')"><img src="'.$GO_THEME->images['addressbook_small'].'" width="16" height="16" border="0" /></a> </td><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id&show_contacts=true\',\'550\',\'400\')">'.$pm_client.'</a>: </td></tr></table></td>';
  60.             echo '<td><input type="hidden" value="'.$load_contact_id.'" name="load_contact_id" /><input type="hidden" value="'.$contact_name.'" name="contact_name" /><input type="text" name="contact_name_text" class="textbox" style="width: 300px;" value="'.$contact_name.'" disabled>';
  61.             echo " <a href='javascript:remove_load_client()' title=\"".$strDeleteItem."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a></td></tr>";
  62.             echo '</td></tr>';
  63.         }
  64.     }?>
  65.     <tr>
  66.         <td>
  67.         <?php
  68.         $load_user_id = isset($_REQUEST['load_user_id']) ? $_REQUEST['load_user_id'] : false;
  69.         if ($GO_MODULES->write_permissions)
  70.         {
  71.             require_once($GO_CONFIG->class_path.'users.class.inc');
  72.             $users = new users();
  73.  
  74.             $ab_module = $GO_MODULES->get_module('addressbook');
  75.  
  76.             if ($load_user_id && $user = $users->get_user($load_user_id))
  77.             {
  78.                 $middle_name = $user['middle_name'] == '' ? '' : $user['middle_name'].' ';
  79.                 $user_name = $user['first_name'].' '.$middle_name.$user['last_name'];
  80.             }else
  81.             {
  82.                 $user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : '';
  83.             }
  84.             echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td><a class="normal" href="javascript:popup(\''.$ab_module['url'].'select.php?show_users=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'select_employer.php&pass_value=id\',\'550\',\'400\')"><img src="'.$GO_THEME->images['addressbook_small'].'" width="16" height="16" border="0" /></a> </td><td><a class="normal" href="javascript:popup(\''.$ab_module['url'].'select.php?show_users=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'select_employer.php&pass_value=id\',\'550\',\'400\')">'.$pm_employee.'</a>: </td></tr></table></td>';
  85.             echo '<td><input type="hidden" value="'.$load_user_id.'" name="load_user_id" /><input type="hidden" value="'.$user_name.'" name="user_name" /><input type="text" name="user_name_text" class="textbox" style="width: 300px;" value="'.$user_name.'" disabled>';
  86.             echo " <a href='javascript:remove_load_user()' title=\"".$strDeleteItem."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a>";
  87.         }else
  88.         {
  89.             $checkbox = new checkbox('load_user_id', $GO_SECURITY->user_id, $pm_yours_only, $load_user_id);
  90.         }
  91.         ?>
  92.         </td>
  93.     </tr>
  94.     <?php
  95.  
  96.     echo '</table>';
  97.     echo '<h3>'.$pm_load_period.':</h3>';
  98.     echo '<table border="0" cellspacing="0" cellpadding="4">';
  99.  
  100.     switch ($show_period)
  101.     {
  102.         case 'all':
  103.             $all_check='checked';
  104.             $period_check = '';
  105.             $month_check = '';
  106.         break;
  107.  
  108.         case 'period':
  109.             $all_check='';
  110.             $period_check = 'checked';
  111.             $month_check = '';
  112.         break;
  113.  
  114.         case 'month':
  115.             $all_check='';
  116.             $period_check = '';
  117.             $month_check = 'checked';
  118.         break;
  119.     }
  120.     echo '<input type="hidden" name="delete_hours" />';
  121.     ?>
  122.     <tr>
  123.         <td height="25" colspan="2">
  124.         <?php
  125.         echo '<input type="radio" name="show_period" value="all" '.$all_check.' />'.$pm_show_all;
  126.         echo '</td></tr><tr><td height="25">';
  127.  
  128.         echo '<input type="radio" name="show_period" value="period" '.$period_check.' />'.$pm_show_period.'</td><td>';
  129.  
  130.         $date = date($_SESSION['GO_SESSION']['date_format'], $time);
  131.  
  132.         $start_date = isset($_GET['start_date']) ? $_GET['start_date'] : $date;
  133.         $datepicker->print_date_picker('start_date', $_SESSION['GO_SESSION']['date_format'], $start_date);
  134.  
  135.         echo '  '.$pm_to.'  ';
  136.  
  137.         $end_date = isset($_GET['end_date']) ? $_GET['end_date'] : $date;
  138.         $datepicker->print_date_picker('end_date', $_SESSION['GO_SESSION']['date_format'], $end_date);
  139.         ?>
  140.         </td>
  141.     </tr>
  142.     <tr>
  143.         <td height="25">
  144.         <input type="radio" name="show_period" value="month" <?php echo $month_check; ?> /><?php echo $pm_show_month; ?>
  145.         </td>
  146.         <td>
  147.         <?php
  148.         for ($i=0;$i<10;$i++)
  149.         {
  150.             $num_years[] = $this_year - $i;
  151.         }
  152.  
  153.         for ($i=1;$i<32;$i++)
  154.         {
  155.             $num_days[] = $i;
  156.         }
  157.  
  158.         for ($i=1;$i<13;$i++)
  159.         {
  160.             $num_months[] = $i;
  161.         }
  162.  
  163.         $dropbox = new dropbox();
  164.         $dropbox->add_arrays($num_months, $months);
  165.         $dropbox->print_dropbox("month", $month);
  166.  
  167.         $dropbox = new dropbox();
  168.         $dropbox->add_arrays($num_years, $num_years);
  169.         $dropbox->print_dropbox("year", $year);
  170.         ?>
  171.         </td>
  172.     </tr>
  173.     <tr>
  174.         <td colspan="2">
  175.         <?php
  176.         $button = new button($cmdOk, "javascript:_load();");
  177.         echo '  ';
  178.         $button = new button($cmdPrint, "javascript:_print();");
  179.         if (isset($fixed_project_id))
  180.         {
  181.             echo '  ';
  182.             $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  183.         }
  184.         ?>
  185.         </td>
  186.     </tr>
  187.     </table>
  188.     <?php
  189. }
  190. if ($task=='load')
  191. {
  192.     $project_id = isset($_GET['project_id']) ? $_GET['project_id'] : 0;
  193.     $load_user_id = isset($_GET['load_user_id']) ? $_GET['load_user_id'] : 0;
  194.     $load_contact_id = isset($_GET['load_contact_id']) ? $_GET['load_contact_id'] : 0;
  195.  
  196.     switch($show_period)
  197.     {
  198.         case 'all':
  199.             $start_time=0;
  200.             $end_time=0;
  201.         break;
  202.  
  203.         case 'period':
  204.             $end_time = date_to_unixtime($_GET['end_date']);
  205.             $start_time = date_to_unixtime($_GET['start_date']);
  206.         break;
  207.  
  208.         case 'month':
  209.             $start_time = mktime(0,0,0,$month, 1, $year);
  210.             $end_time = mktime(0,0,0,$month+1, 1, $year);
  211.         break;
  212.     }
  213.  
  214.     $projects->get_hours($start_time, $end_time, $project_id, $load_user_id, $load_contact_id);
  215.  
  216.     echo '<table border="0" cellpadding="4" cellspacing="0">';
  217.     echo '<tr>';
  218.     echo '<td><h3>'.$pm_starttime.'</h3></td>';
  219.     echo '<td><h3>'.$pm_endtime.'</h3></td>';
  220.     if ($load_user_id == 0)
  221.     {
  222.         echo '<td><h3>'.$pm_employee.'</h3></td>';
  223.     }
  224.     if ($project_id == 0)
  225.     {
  226.         echo '<td><h3>'.$pm_project.'</h3></td>';
  227.         if ($load_contact_id == 0)
  228.         {
  229.             echo '<td><h3>'.$pm_client.'</h3></td>';
  230.         }
  231.     }
  232.     echo '<td align="center"><h3>'.$pm_hours.'</h3></td>';
  233.     echo '<td align="left"><h3>'.$pm_fee.'</h3></td>';
  234.     echo '<td align="right"><h3>'.$pm_breaktime.'</h3></td>';
  235.     echo '<td align="right"><h3>'.$pm_unit_value.'</h3></td>';
  236.     echo '<td align="center"><h3>'.$pm_units.'</h3></td>';
  237.     echo '<td></td></tr>';
  238.  
  239.     $last_date = '';
  240.     $total_days = 0;
  241.     $total_hours = 0;
  242.     $total_fee = 0;
  243.     $class = 'TableInside1';
  244.  
  245.     while($projects->next_record())
  246.     {
  247.         $local_start_time = date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $projects->f('start_time')+($_SESSION['GO_SESSION']['timezone']*3600));
  248.         $local_end_time = date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $projects->f('end_time')+($_SESSION['GO_SESSION']['timezone']*3600));
  249.  
  250.         if ($projects->f('unit_value') > 0)
  251.         {
  252.             $unit_value = $projects->f('unit_value');
  253.             $break_time = '-';
  254.             $units = ($local_end_time - $local_start_time)*60/$unit_value;
  255.         }else
  256.         {
  257.             $unit_value = '-';
  258.             $units = '-';
  259.             $break_time = date($_SESSION['GO_SESSION']['time_format'], $projects->f('break_time')+mktime(0,0,0,1,1,1970));
  260.         }
  261.         $hours = ($projects->f('end_time') - $projects->f('start_time') - $projects->f('break_time'))/3600;
  262.  
  263.         if ($projects->f('fee_value') > 0)
  264.         {
  265.             $fee_string = htmlentities($_SESSION['GO_SESSION']['currency']).' '.number_format($projects->f('fee_value'), 2, $_SESSION['GO_SESSION']['decimal_seperator'],$_SESSION['GO_SESSION']['thousands_seperator']).' / '.$projects->f('fee_time').' '.$pm_mins;
  266.             $fee_per_hour = ($projects->f('fee_value')/$projects->f('fee_time'))*60;
  267.             $fee = $fee_per_hour*$hours;
  268.             $total_fee += $fee;
  269.         }else
  270.         {
  271.             $fee_string = '0';
  272.         }
  273.  
  274.         $date = date($_SESSION['GO_SESSION']['date_format'], $projects->f('start_time'));
  275.         if ($date != $last_date) $total_days++;
  276.         $last_date = $date;
  277.  
  278.         $total_hours += $hours;
  279.         echo '<tr class="'.$class.'">';
  280.         echo '<td valign="top" nowrap>'.$local_start_time.'</td>';
  281.         echo '<td valign="top" nowrap>'.$local_end_time.'</td>';
  282.         if ($load_user_id == 0)
  283.         {
  284.             echo '<td valign="top" nowrap>'.show_profile($projects->f('user_id')).'</td>';
  285.         }
  286.         if ($project_id == 0)
  287.         {
  288.             echo '<td valign="top" nowrap><a href="project.php?project_id='.$projects->f('project_id').'" class="normal">'.$projects->f('name').' ('.$projects->f('description').')</a></td>';
  289.             if ($load_contact_id == 0)
  290.             {
  291.                 echo '<td valign="top" nowrap>'.show_contact($projects->f('contact_id')).'</td>';
  292.             }
  293.         }
  294.  
  295.         echo '<td align="center" valign="top">'.$hours.'</td>';
  296.         echo '<td align="left" valign="top">'.$fee_string.'</td>';
  297.         echo '<td align="right" valign="top">'.$break_time.'</td>';
  298.         echo '<td align="right" valign="top">'.$unit_value.'</td>';
  299.         echo '<td align="center" valign="top">'.$units.'</td>';
  300.  
  301.         echo "<td valign=\"top\">";
  302.         if (!$print)
  303.         {
  304.             echo "<a href='javascript:confirm_action(\"javascript:delete_hours(".$projects->f("id").")\",\"".rawurlencode($strDeletePrefix.' '.$pm_this_entry.' '.$strDeleteSuffix)."\")' title=\"".$strDeleteItem." ".$pm_entry."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a>";
  305.         }
  306.         echo "</td></tr>\n";
  307.  
  308.         if ($projects->f('comments') != '')
  309.         {
  310.             echo '<tr class="'.$class.'"><td valign="top" colspan="99">'.text_to_html($projects->f('comments')).'</td></tr>';
  311.         }
  312.  
  313.         if ($class != 'TableInside2') $class='TableInside2'; else $class='TableInside1';
  314.     }
  315.  
  316.     echo '</table><br /><h3>'.$pm_summary .'</h3>';
  317.     echo '<table border="0">';
  318.     echo'<tr><td><i>'.$pm_total_hours.':</td><td>'.$total_hours.'</i></td></tr>';
  319.     echo'<tr><td><i>'.$pm_total_days.':</td><td>'.$total_days.'</i></td></tr>';
  320.     echo'<tr><td><i>'.$pm_total_fee.':</td><td>'.htmlentities($_SESSION['GO_SESSION']['currency']).' '.number_format($total_fee, 2, $_SESSION['GO_SESSION']['decimal_seperator'],$_SESSION['GO_SESSION']['thousands_seperator']).'</i></td></tr>';
  321.     echo '</table>';
  322. }
  323. ?>
  324. <input type="hidden" name="print" />
  325.  
  326. <script type="text/javascript" langauge="javascript">
  327. function delete_hours(id)
  328. {
  329.     document.projects_form.task.value='load';
  330.     document.projects_form.delete_hours.value=id;
  331.     document.projects_form.submit();
  332. }
  333.  
  334. function remove_load_client()
  335. {
  336.     document.projects_form.load_contact_id.value = 0;
  337.     document.projects_form.contact_name.value = '';
  338.     document.projects_form.contact_name_text.value = '';
  339. }
  340.  
  341. function remove_load_user()
  342. {
  343.     document.projects_form.load_user_id.value = 0;
  344.     document.projects_form.user_name.value = '';
  345.     document.projects_form.user_name_text.value = '';
  346. }
  347.  
  348. function _print()
  349. {
  350.     document.projects_form.task.value='load';
  351.     document.projects_form.print.value = 'true';
  352.     document.projects_form.target = '_blank';
  353.     document.projects_form.action = '<?php echo $module_url; ?>print.php';
  354.     document.projects_form.submit();
  355.     document.projects_form.task.value='load';
  356.     document.projects_form.print.value = 'false';
  357.     document.projects_form.action = '<?php echo $_SERVER['PHP_SELF']; ?>';
  358.     document.projects_form.target = '_self';
  359.  
  360. }
  361.  
  362. function _load()
  363. {
  364.     document.projects_form.task.value='load';
  365.     document.projects_form.print.value = 'false';
  366.     document.projects_form.target = '_self';
  367.     document.projects_form.action = '<?php echo $_SERVER['PHP_SELF']; ?>';
  368.     document.projects_form.submit();
  369. }
  370. </script>
  371.