home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / example / index.php
PHP Script  |  2004-03-08  |  7KB  |  220 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. How to create a typical Group-Office module
  14.  
  15. To see this example working open Group-office go to the menu: administrator->modules
  16. select the module named: 'example' and click at the 'save' button.
  17.  
  18.  
  19. Now go to the menu: applications->example !
  20.  
  21. SOME CODING RULES:
  22.  
  23. 1. Always use '<?php' not '<?'
  24. 2. code readable functions should be put in this form:
  25.  
  26. funtion example($example_var1, $example_var2)
  27. {
  28.     //this is a comment
  29.     if($example_var1)
  30.     {
  31.         $example_var1 = '';
  32.     }else
  33.     {
  34.         $example_var2 = '';
  35.     }
  36.  
  37.     return true;
  38. }
  39.  
  40. 3. use single quotes rather then double quotes
  41. 4. don't double code. Try to re use every single line of code on other pages.
  42.    so when something changes there is only place to edit
  43. 5. create classes
  44. 6. Examine existing code. The classes the stylesheet. The common.Language.inc files so you won;t double code.
  45.    Also look at other modules to get more understanding of the system
  46.    very important classes are:
  47.    security.class.inc
  48.    users.class.inc
  49.    addressbook.class.inc
  50.    modules.class.inc
  51.    filesystem.class.inc
  52.  
  53.    also take a look at the controls:
  54.    acl_control.inc
  55. 7. Use correct names. Includable documents should be named *.inc and normal files *.php
  56.    classes are called: *.class.inc
  57.  
  58. 8. Use the multi-language method for Group-Office see the language folder.
  59.    While doing this know that you can always use the common language vars. See 'common.<language>.inc'.
  60. 9. When developing set php notices on in php.ini. This way you have to declare every variable and this is
  61.    a good habit.
  62.  
  63.  
  64.  
  65. //first add some info:
  66.  
  67. Copyright Intermesh 2003
  68. Author: Merijn Schering <mschering@intermesh.nl>
  69. Version: 1.0 Release date: 08 July 2003
  70.  
  71. This program is free software; you can redistribute it and/or modify it
  72. under the terms of the GNU General Public License as published by the
  73. Free Software Foundation; either version 2 of the License, or (at your
  74. option) any later version.
  75.  
  76.  
  77. require the Group-Office.php file
  78. This creates:
  79.  
  80. $GO_CONFIG - configuration settings - see GroupOffice.php
  81. $GO_SECURITY - security class - see classes/security.class.inc
  82. $GO_LANGUAGE - language class - not really relevant now
  83. $GO_THEME - theme class - not really relevant now
  84.  
  85. */
  86. require("../../Group-Office.php");
  87.  
  88. //authenticate the user
  89. //if $GO_SECURITY->authenticate(true); is used the user needs admin permissons
  90.  
  91. $GO_SECURITY->authenticate();
  92.  
  93. //see if the user has access to this module
  94. //for this to work there must be a module named 'example'
  95. $GO_MODULES->authenticate('example');
  96.  
  97. //set the page title for the header file
  98. $page_title = "Example";
  99. //require the header file. This will draw the logo's and the menu
  100. // there is also the simple_header.inc file without logo's and menu
  101. require($GO_THEME->theme_path."header.inc");
  102. //put html in a table because margins are set to 0
  103. ?>
  104. <table border="0" cellpadding="10">
  105. <tr>
  106.     <td>
  107.     <h1>Example module for starting Group-Office developers</h1>
  108.     <?php
  109.     //put module code here!
  110.     //severall control classes are available from controls.class.inc
  111.  
  112.     //the $cmdOk var comes from languages/common.Language.php. take a look at that file.
  113.     //the strings from the file can be used everywhere inside Group-Office
  114.  
  115.     //button control
  116.     $button = new button($cmdOk, "javascript:alert('You clicked on a Group-Office button!')");
  117.  
  118.     echo '<br /><br />';
  119.  
  120.     //dropbox control
  121.     //always declare vars in Group-Office!
  122.     $dropdown = isset($dropdown) ? $dropdown : '2';
  123.     $dropbox = new dropbox();
  124.     $dropbox->add_value('1', 'one');
  125.     $dropbox->add_value('2', 'two');
  126.     $dropbox->add_value('3', 'three');
  127.     $dropbox->print_dropbox('dropdown', $dropdown);
  128.  
  129.     echo '<br /><br />';
  130.  
  131.     //or direct database link:
  132.  
  133.     //this is how you should load a class:
  134.     require_once($GO_CONFIG->class_path.'users.class.inc');
  135.     //create a users object:
  136.     $users = new users();
  137.     //this function gets all users
  138.     $users->get_users();
  139.     //we can now pass the users object to the dropdown box and add all the users to it
  140.     //declare the user var
  141.     $user = isset($user) ? $user : '0';
  142.     $dropbox = new dropbox();
  143.     //add the users class, use 'id' for value and 'name' for text
  144.     $dropbox->add_sql_data('users', 'id', 'name');
  145.     //print the dropbox
  146.     $dropbox->print_dropbox('user',$user);
  147.  
  148.     echo '<br /><br />';
  149.  
  150.     //statusbar control
  151.     $statusbar = new statusbar();
  152.     $statusbar->info_text = 'Group-Office usage';
  153.     $statusbar->turn_red_point = 90;
  154.     $statusbar->print_bar(75, 100);
  155.  
  156.     //how do you get user info
  157.  
  158.     //the current user is stored in:
  159.     echo 'Your user ID is "'.$GO_SECURITY->user_id.'"<br />';
  160.     $user = $users->get_user($GO_SECURITY->user_id);
  161.     echo 'Your name is "'.$user['name'].'"<br /><br />';
  162.  
  163.     //now for some permission management.
  164.     //You can secure an object by giving it an ACL (Access Control List). When the user
  165.     //you logged in with was created it also got an ACL. This acl is used to protect your personal profile.
  166.     //We already got the user information in the above example so the user acl = stored in $user['acl_id'].
  167.     //So if we want to set the permissions this can be done really easily with the control: 'acl_control.inc'
  168.  
  169.     echo 'This user is visible to:<br />';
  170.  
  171.     //The acl_control must always be put in a form.
  172.     echo '<form name="save" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  173.     //we set the following for the control
  174.     $acl_control_acl_id = $user["acl_id"];
  175.     //we hide ourself because we do not need to protect ourself from us.
  176.     $acl_control_hide_self = true;
  177.     //TIP: look in this file for more options.
  178.  
  179.     //we actually require the control here
  180.     require($GO_CONFIG->control_path."acl_control.inc");
  181.     //and we need a buttton to update this and that's all what's to it.
  182.     $button = new button($cmdSave, 'javascript:document.forms[0].submit()');
  183.  
  184.     //When you are creating your own secured objects you just call th e function: $GO_SECURITY->get_new_acl()
  185.     //to create a new ACL.
  186.  
  187.     echo '<br /><br />';
  188.  
  189.     echo '<p><b>A dropbox filled with grouped contacts</b></p>';
  190.  
  191.     //Now we put some things in a table with tabs NOTE 'html_table.inc' is deprecated the class below should be used.
  192.  
  193.     //                            ID                        TITLE                 WIDTH  HEIGHT
  194.     $tabtable = new tabtable('example_tabtable', 'Example tab window title', '600', '400');
  195.     //                    ID      TITLE
  196.     $tabtable->add_tab('tab_1', 'Tab 1');
  197.     $tabtable->add_tab('tab_2', 'Tab 2');
  198.  
  199.     $tabtable->print_head();
  200.     switch($tabtable->get_active_tab_id())
  201.     {
  202.         case 'tab_1':
  203.             echo 'This is content in tab 1!';
  204.         break;
  205.  
  206.         case 'tab_2':
  207.             echo 'This is content in tab 2!';
  208.         break;
  209.     }
  210.     $tabtable->print_foot();
  211.     ?>
  212.     </td>
  213. </tr>
  214. </table>
  215. <?php
  216. //require the footer file
  217. require($GO_THEME->theme_path."footer.inc");
  218. ?>
  219.  
  220.