EquinoxWorld
08-17-2011, 02:16 AM
Hello everyone, I was wondering if anyone knew by any chance where i could find how calendars are created (after saving through admin panel), I ask because I have successfully created a new calendar with a SQL query to add the record in the "calendar" table ; I even see the new calendar in the admin panel and I can edit it's settings but I can't view it nor it appears on the "Calender Picker" drop down menu from the forums. If I try and view it from the admin panel I get a invalid permissions page so I'm guessing it's not as direct as a simple SQL query, I image there's some permissions that need to be updated somewhere?? I checked my own permissions and I am able to view all other calendars except that one. Any9one have any ideas what I could be missing?
The idea I have is the following...
I want to have a calendar on the home page of my mod that updates weekly according to what the moderator of the mod inserts (events). I was able to embed the calendar successfully in my page and had the permissions changed so that everyone can view this calendar with the events that the "chosen" moderator places. At the same time the calendar will be updated every time the cron file runs at whatever time the moderator places the event. I am half way there...
The calendar appears successfully and permissions are correct to view. I have also been able to have the back-end for the moderator created for him/her to add events and no one else (another option is added for the admin to provide the user id of the contest moderator(s)) and this is used within the calendar code; meaning everyone who views this page the calendar assumes it's user_id x and views only the events we control. Next step would be creating the code for the creation of the calendar (initially when the mod installs; this is my initial question for this thread :p). After that it's a matter of syncing the cron and the events and voil?... Got a bit of track there so about that everyone. Needed to vent my thoughts a bit. :D
Any way if anyone has any ideas or thoughts about how to create a new calendar with proper permisisons please don't be shy. Sharing is caring everyone, specially knowledge. ;) Thanks for your time everyone. Please let me know your thoughts. Have a good night everyone.
Best Regards.
nhawk
08-17-2011, 11:34 AM
Calendars are created in admincalendar.php. The saving portion is just an sql that parses the data from the routine in admincalendar.php.
By default, calendar permissions are empty (as in no permissions exist for a calendar) which allows all members all access and that information is held in the calendarpermission table as a bitfield total. So I don't think that's the problem unless you wrote something to that table for that calendar.
You may not have set all of the fields in the calendar and that might be a problem. Also, you need to be careful because at least one of the fields is a bitfield total. And another is an array definition for emails (not just an array of emails).
EquinoxWorld
08-17-2011, 11:49 AM
Calendars are created in admincalendar.php. The saving portion is just an sql that parses the data from the routine in admincalendar.php.
By default, calendar permissions are empty (as in no permissions exist for a calendar) which allows all members all access and that information is held in the calendarpermission table as a bitfield total. So I don't think that's the problem unless you wrote something to that table for that calendar.
You may not have set all of the fields in the calendar and that might be a problem. Also, you need to be careful because at least one of the fields is a bitfield total. And another is an array definition for emails (not just an array of emails).
Thanks for your reply nhawk. That's exactly where I was looking at yesterday but at 1 am your mind can't grasp things as best as it can. :) I was looking particualrly at this bit of code:
if ($_REQUEST['do'] == 'add')
{
// need to set default yes permissions!
$calendar = array(
'active' => 1,
'allowbbcode' => 1,
'allowimgcode' => 1,
'allowsmilies' => 1,
'startofweek' => 1,
'showholidays' => 1,
'showbirthdays' => 1,
'showweekends' => 1,
'cutoff' => 40,
'eventcount' => 4,
'birthdaycount' => 4,
'daterange' => $exampledaterange,
'usetimes' => 1,
'usetranstime' => 1,
'showupcoming' => 1,
);
$maxdisplayorder = $db->query_first("
SELECT MAX(displayorder) AS displayorder
FROM " . TABLE_PREFIX . "calendar
");
$calendar['displayorder'] = $maxdisplayorder['displayorder'] + 1;
print_table_header($vbphrase['add_new_calendar']);
}
That's the only place I can think see that has to do with add a calendar. What I don't see is that query to insert into database. I don't quite understand how it inserts these new values . There is an else condition right after the code above but I believe it's for editing existing calendars. Basically I would need to add this code into some sort of function and have it run when the install script for the mod runs. What I would need specify is the title of the calendar basically. About what I tried before is duplicate with an SQL query another calendar with the same values that it had in the database table except change the id to the next one, same permissions same everything else, maybe that was the problem in itself, it would be definitely better to code it this way using what vb uses to create calendars.
nhawk
08-17-2011, 12:05 PM
Ok, something to keep in mind, you NEVER assign a value to the first field in any table (in this case, calendarid). You don't even specify it in your save SQL. That field auto-increments and should never be assigned a value in any query that adds a record to the table.
The save routine IS this..
$db->query_write(fetch_query_sql($vbulletin->GPC['calendar'], 'calendar'));
I said to just ignore it because all it does is parse the calendar data into the calendar table. Other than the parse, there's nothing special about it. The fetch_query_sql is in includes/functions.php if you want to look at it.
If you just duplicated an existing calendar that you can view (with a different name I hope), there's no reason why it shouldn't work.
So far as that code, it's not really needed if you write directly to the table with known values.
--------------- Added 1313587108 at 1313587108 ---------------
Just to be sure I'm not talking out of my hind end, I just added a calendar with all of the same settings as the default calendar on my dev server by a direct SQL add and it does work.
The only settings I changed were the calendar name, and the display order.
EquinoxWorld
08-17-2011, 12:45 PM
Ok, something to keep in mind, you NEVER assign a value to the first field in any table (in this case, calendarid). You don't even specify it in your save SQL. That field auto-increments and should never be assigned a value in any query that adds a record to the table.
The save routine IS this..
$db->query_write(fetch_query_sql($vbulletin->GPC['calendar'], 'calendar'));
I said to just ignore it because all it does is parse the calendar data into the calendar table. Other than the parse, there's nothing special about it. The fetch_query_sql is in includes/functions.php if you want to look at it.
If you just duplicated an existing calendar that you can view (with a different name I hope), there's no reason why it shouldn't work.
So far as that code, it's not really needed if you write directly to the table with known values.
--------------- Added 1313587108 at 1313587108 ---------------
Just to be sure I'm not talking out of my hind end, I just added a calendar with all of the same settings as the default calendar on my dev server by a direct SQL add and it does work.
The only settings I changed were the calendar name, and the display order.
Thanks for your reply, understood sensei :). I knew that I couldn't assign an id because that field is auto-increment but I wasn't sure about the permissions. I tried what you said and duplicated the calendar via SQL but with a different name and display order and it works too. I can see it fine now, what I was doing yesterday I was duplicating a nmew calendar I had created and not the default one, maybe that was causing some sort of issue. I took note of the php SQL code used ot create the calendar and saved it for the install script.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$sql = 'INSERT INTO `calendar` (`calendarid`, `title`, `description`, `displayorder`, `neweventemail`, `moderatenew`, `startofweek`, `options`, `cutoff`, `eventcount`, `birthdaycount`, `startyear`, `endyear`, `holidays`) VALUES (NULL, \'Default Calendar Bz\', \'\', \'4\', \'a:0:{}\', \'0\', \'1\', \'631\', \'40\', \'4\', \'4\', \'2008\', \'2014\', \'0\');';
I can just use this with certain variables assigned of course at my install script and I don't have to deal with anything else creating the calendar.
What comes to mind creating the calendar, setting a custom name for it "Contest Of The Week" then use that name to get the calendar id to display it in my page with the code I have now which all I have to specify is which calendar id it is.
Thank you so much for your help nhawk. Can't wait for you to see what all this works been about ;) I think people are really going to enjoy this. There's nothing out there right now like it, as far as I know anyway.
UPDATE:
The SQL works perfect. I just used the id of the calendar in my page to show the new calendar I created with the SQL query and it shows fine, for me and everyone else! :) Thanks again.
--------------- Added 1313591950 at 1313591950 ---------------
Using this to add events:
$sql = 'INSERT INTO `event` (`eventid`, `userid`, `event`, `title`, `allowsmilies`, `recurring`, `recuroption`, `calendarid`, `customfields`, `visible`, `dateline`, `utc`, `dst`, `dateline_from`, `dateline_to`) VALUES (NULL, \'1\', \'\', \'Signature Of The Week #2\', \'1\', \'0\', \'\', \'2\', \'a:0:{}\', \'1\', \'1313591803\', \'0.00\', \'0\', \'1314144000\', \'0\');';
Using this to add cron job:
$sql = 'INSERT INTO `cron` (`cronid`, `nextrun`, `weekday`, `day`, `hour`, `minute`, `filename`, `loglevel`, `active`, `varname`, `volatile`, `product`) VALUES (NULL, \'1313942400\', \'0\', \'-1\', \'12\', \'a:1:{i:0;i:-1;}\', \'./includes/cron/cotw_func_sotw_recycle.php\', \'0\', \'1\', \'cotw_recycle2\', \'1\', \'cotw\');';
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.