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