Author Topic: Show week numbers in Calendar  (Read 4339 times)

neoasix

  • Newbie
  • *
  • Posts: 5
    • View Profile
Show week numbers in Calendar
« on: April 17, 2009, 08:15:01 am »
Hi,

great tool.  :)

is it possible to turn on week numbers in Calendar ??? ???

thx for help  ;D

conrado

  • Administrator
  • Hero Member
  • *****
  • Posts: 998
  • Conrado
    • View Profile
    • Feng Office
    • Email
Re: Show week numbers in Calendar
« Reply #1 on: April 20, 2009, 04:37:08 pm »
Could you explain in more detail?

Thank you
Get Official Support for your Feng Office. Support the development team. Sign up for a Free Trial here.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #2 on: April 21, 2009, 10:03:47 am »
A lot of people work with week numbers when planning

I looked at the code in calender.php, which makes the view, and it can be added.

If you are interested, I'll post it, but you won't be able to turn it on and off, and it will probably disappear with the next update.
If you are what you eat, then I'm fast, cheap and easy.

conrado

  • Administrator
  • Hero Member
  • *****
  • Posts: 998
  • Conrado
    • View Profile
    • Feng Office
    • Email
Re: Show week numbers in Calendar
« Reply #3 on: April 21, 2009, 10:13:45 am »
Hey Ras200,

Contributions are always welcome! I've believe some of your code contributions were already picked up by core developers, right?

This is not a promise that every contribution will be bundled in the core (we should like what the feature does, and at least be easy to adapt to the internal coding style), but we do at least evaluate all.

Did I mention I like your signature?
Get Official Support for your Feng Office. Support the development team. Sign up for a Free Trial here.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #4 on: April 21, 2009, 10:20:21 am »
Hey Conrado, thanks for the kind words!

I'll make it an option in user settings under the calendar panel and add the code to the view file.

Then I'll submit the code here, and the core developers can decide whether or not to go by it.

Even if it's not picked up, it fairly easy to do, and I can use it for myself.
If you are what you eat, then I'm fast, cheap and easy.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #5 on: April 22, 2009, 07:41:32 am »
Make week numbers available in calendar, month view.

Change setting for calendar panel

UPDATE `opengoo`.`og_user_ws_config_categories` SET `is_system` = '0' WHERE `og_user_ws_config_categories`.`id` = 5;

Add option in user_config

INSERT INTO `opengoo`.`og_user_ws_config_options` (
`id` ,
`category_name` ,
`name` ,
`default_value` ,
`config_handler_class` ,
`is_system` ,
`option_order` ,
`dev_comment`
)
VALUES (
NULL , 'calendar panel', 'show_week_numbers', '0', 'BoolConfigHandler', '0', '0', NULL
);

Add in language/en_us/administrations.php (Or whatever language folder you are using)(in my file I've added it as line 95)
     'user ws config category name calendar panel' => 'Calendar',

Add in language/en_us/administrations.php (Or whatever language folder you are using)(in my file I've added it as line 115-116)
     'user ws config option name show_week_numbers' => 'Show week numbers',
     'user ws config option desc show_week_numbers' => 'Will show week numbers in calendar',

Add in language/en_us/calendar.php (Or whatever language folder you are using)(in my file I've added it as line 134)
   "week" => "week",

Add in application/views/event/calendar.php (line 45 in my file)
$firstweek = date("W", mktime(0, 0, 0, $month, 1, $year));

Change in application/views/event/calendar.php (line 91 to 113 in my file)
               <tr>
               <?php
               if(!cal_option("start_monday")) {
               ?>
                  <th width="14%"> <?php echo lang('sunday short') ?> </th>
               <?php } ?>
               <th width="14%"><?php echo  lang('monday short') ?></th>
               <th width="14%"><?php echo  lang('tuesday short') ?></th>
               <th width="14%"><?php echo  lang('wednesday short') ?></th>
               <th width="14%"><?php echo  lang('thursday short') ?></th>
               <th width="14%"><?php echo  lang('friday short') ?></th>
               <th width="14%"><?php echo  lang('saturday short') ?></th>
               
               <?php
               $output = '';
               if(cal_option("start_monday")) {
               ?>
                  <th width="14%"> <?php echo lang('sunday short') ?> </th>
               <?php } ?>
 to
 
                <tr>
               <?php
               if(cal_option("show_week_numbers")) {
               ?>
                  <th width="2%"> <?php echo lang('week') ?> </th>
               <?php }
               if(!cal_option("start_monday")) {
               ?>
                  <th width="14%"> <?php echo lang('sunday short') ?> </th>
               <?php } ?>
               <th width="14%"><?php echo  lang('monday short') ?></th>
               <th width="14%"><?php echo  lang('tuesday short') ?></th>
               <th width="14%"><?php echo  lang('wednesday short') ?></th>
               <th width="14%"><?php echo  lang('thursday short') ?></th>
               <th width="14%"><?php echo  lang('friday short') ?></th>
               <th width="14%"><?php echo  lang('saturday short') ?></th>
               
               <?php
               $output = '';
               if(cal_option("start_monday")) {
               ?>
                  <th width="14%"> <?php echo lang('sunday short') ?> </th>
               <?php } ?>

change function
function cal_load_options(){
   global $cal_db, $cal_options;
   // Find current user id
   $id = $_SESSION['cal_userid'];
   // call the DB for options
   $result = cal_query_getoptions($id);
   // get all options
   $d = array();
   while($t = $cal_db->sql_fetchrow($result)){
      $d[$t['name']] = $t['value'];
   }
   // set the options that have values
   if(array_var($d,'timeout')!="")       $cal_options['timeout'] = $d['timeout'];
   if(array_var($d,'skin')!="")          $cal_options['skin'] = $d['skin'];
   if(array_var($d,'language')!="")       $cal_options['language'] = $d['language'];
   if(array_var($d,'root_password')!="") $cal_options['root_password'] = $d['root_password'];
   // set the options that are true or false
   if(array_var($d,'show_times')=='y')    $cal_options['show_times'] = TRUE;
   else                   $cal_options['show_times'] = FALSE;
   if(array_var($d,'hours_24')=='y')    $cal_options['hours_24'] = TRUE;
   else                   $cal_options['hours_24'] = FALSE;
   if(array_var($d,'start_monday')=='1') $cal_options['start_monday'] = TRUE;
   else                   $cal_options['start_monday'] = FALSE;
   if(array_var($d,'anon_naming')=='y')    $cal_options['anon_naming'] = TRUE;
   else                   $cal_options['anon_naming'] = FALSE;
}
in library/cal/cal_gatekeeper.php to
function cal_load_options(){
   global $cal_db, $cal_options;
   // Find current user id
   $id = $_SESSION['cal_userid'];
   // call the DB for options
   $result = cal_query_getoptions($id);
   // get all options
   $d = array();
   while($t = $cal_db->sql_fetchrow($result)){
      $d[$t['name']] = $t['value'];
   }
   // set the options that have values
   if(array_var($d,'timeout')!="")       $cal_options['timeout'] = $d['timeout'];
   if(array_var($d,'skin')!="")          $cal_options['skin'] = $d['skin'];
   if(array_var($d,'language')!="")       $cal_options['language'] = $d['language'];
   if(array_var($d,'root_password')!="") $cal_options['root_password'] = $d['root_password'];
   // set the options that are true or false
   if(array_var($d,'show_times')=='y')    $cal_options['show_times'] = TRUE;
   else                   $cal_options['show_times'] = FALSE;
   if(array_var($d,'hours_24')=='y')    $cal_options['hours_24'] = TRUE;
   else                   $cal_options['hours_24'] = FALSE;
   if(array_var($d,'start_monday')=='1') $cal_options['start_monday'] = TRUE;
   else                   $cal_options['start_monday'] = FALSE;
   if(array_var($d,'show_week_numbers')=='1') $cal_options['show_week_numbers'] = TRUE;
   else                   $cal_options['show_week_numbers'] = FALSE;
   if(array_var($d,'anon_naming')=='y')    $cal_options['anon_naming'] = TRUE;
   else                   $cal_options['anon_naming'] = FALSE;
}

change function cal_query_getoptions in library/cal/queries/mysql.php from whatever it is to
function cal_query_getoptions($id){
   global $cal_db;
   $q = 'SELECT name, value
      FROM `og_user_ws_config_options`
      INNER JOIN `og_user_ws_config_option_values` ON `id` = `option_id`
      WHERE `category_name` = "calendar panel" AND `user_id` = ' . $id . '
      LIMIT 0 , 30';
   $r = $cal_db->sql_query($q);
   if(!$r AND DEBUG){
      echo $cal_db->sql_error();
   }
   return $r;
}

Add following lines in public/assets/themes/default/stylesheets/custom.css (if it does not exist, it needs to be created)
#calendar td.weeknumber{
  text-align: center;
  color: white;
  background-color: #339;
  border: #999999 1px solid;
  }

It will take some time to set in, there is a cached css file that doesn't update until I've restarted my computer.
If you are what you eat, then I'm fast, cheap and easy.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #6 on: April 22, 2009, 07:54:29 am »
Sorry, left out the most important part
in calendar.php change
               for ($week_index = 0;; $week_index++) {
               ?>
                  <tr>
               <?php

to
               for ($week_index = 0;; $week_index++) {
               ?>
                  <tr>
               <?php
               if(cal_option("show_week_numbers")) {
               ?>
                     <td class="weeknumber" valign="top"><?php echo $week_index + $firstweek?></td>
               <?php

If you are what you eat, then I'm fast, cheap and easy.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #7 on: April 22, 2009, 09:15:56 am »
Best argument for the developer team NOT taking this in is in the table buildup.
I changed the width of the weekday table cells from 2X15% and 5X14% to 7X14% and used the extra 2% for the weeknumber column.

Messy code, a no-no.

I do however think it should just be there, not as a choice, but standard. If you don't need it/use it, it doesn't take up much space, and for us that do plan in weeks, it's really a necessity.
If you are what you eat, then I'm fast, cheap and easy.

Pet

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 638
  • Always mining for solutions!
    • View Profile
    • The Bet!
Re: Show week numbers in Calendar
« Reply #8 on: April 22, 2009, 03:26:35 pm »
nice that you posted this ras
Support OpenGoo - Sponsor a Feature! | Follow me on Twitter | OG Support Chat | Did you turn debugging on?

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Show week numbers in Calendar
« Reply #9 on: May 07, 2009, 06:52:44 am »
The chosen code in version 1.4 is a lot messier than the one I wrote, and that was plenty messy!
If you are what you eat, then I'm fast, cheap and easy.