Author Topic: Starting the week with a monday  (Read 2876 times)

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Starting the week with a monday
« on: April 15, 2009, 07:27:04 am »
Working in Denmark, we prefer seeing the calendar starting the week with monday.

Looking through the code in cal_gatekeeper.php, I can see that it seeks an option called start_monday in the db through a function called cal_query_getoptions().

This function is blocked out however, so I can't see where to set this property.

Does anyone know where I can set this value?
If you are what you eat, then I'm fast, cheap and easy.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Starting the week with a monday
« Reply #1 on: April 17, 2009, 07:02:46 am »
Change setting on the calendar panel

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

Add post to config options

"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', 'start_monday', 'n', 'StringConfigHandler', '0', '600', 'Sets whether the week starts on monday or sunday'
) "

Add following line in language/en_us/administration.php (or in whatever language folder you're using)

     'user ws config category name calendar panel' => 'Calendar',
For example line 95.

Add following lines in language/en_us/administration.php (or in whatever language folder you're using)

     'user ws config option name start_monday' => 'Start week on monday',
     'user ws config option desc start_monday' => 'Will show the calendar starting weeks on a monday',
For example lines 113 - 114.

The function cal_load_options() i "library/cal/cal_gatekeeper.php" is changed 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,'anon_naming')=='y')    $cal_options['anon_naming'] = TRUE;
   else                   $cal_options['anon_naming'] = FALSE;
}

The function cal_query_getoptions() i "library/cal/queries/mysql.php" is changed 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;
}

Now the user can set the value in account settings.
If you are what you eat, then I'm fast, cheap and easy.

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Starting the week with a monday
« Reply #2 on: April 17, 2009, 08:13:38 am »
One other change, in the file apllication/views/event/viewweek.php, the line
   $startday = date("d", mktime(0, 0, 0, $month, $day, $year)) - (date("N", mktime(0, 0, 0, $month, $day, $year)) % 7);//inicio de la semana

Should be replaced with
   if (!cal_option("start_monday")){
      $startday = date("d", mktime(0, 0, 0, $month, $day, $year)) - (date("N", mktime(0, 0, 0, $month, $day, $year)) % 7);//beginning of the week, sunday
   }else{
      $startday = date("d", mktime(0, 0, 0, $month, $day, $year)) - (date("n", mktime(0, 0, 0, $month, $day, $year)) % 7);//beginning of the week, monday
   }
If you are what you eat, then I'm fast, cheap and easy.

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: Starting the week with a monday
« Reply #3 on: April 17, 2009, 06:15:37 pm »
Hi,

Thank you very much for your contribution !!!

We made some changes to the code in order to integrate it to next release, and it's working perfectly!
This feature will be available in version 1.4.
thanks!

ras2000

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Proremus
Re: Starting the week with a monday
« Reply #4 on: April 21, 2009, 07:58:04 am »
Sorry mistake in the viewweek.php code it should be
   if (cal_option("start_monday") == 0){
      $startday = date("d", mktime(0, 0, 0, $month, $day, $year)) - (date("N", mktime(0, 0, 0, $month, $day, $year)) % 7);//previous sunday
   }else{
      $startday = date("d", mktime(0, 0, 0, $month, $day, $year)) - (date("N", mktime(0, 0, 0, $month, $day, $year)) % 7) + 1;//previous monday
   }
   $endday = $startday + 7;//fin de la semana

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