Zikula_Value_Addons
[ class tree: Zikula_Value_Addons ] [ index: Zikula_Value_Addons ] [ all elements ]

Source for file pnadmin.php

Documentation is available at pnadmin.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2002, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnadmin.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Value_Addons
  10.  * @subpackage Banners
  11.  */
  12.  
  13. /**
  14.  * the main administration function
  15.  *
  16.  * @author       Devin Hayes
  17.  * @return       output       The main module admin page.
  18.  */
  19. function Banners_admin_main()
  20. {
  21.     // Security check
  22.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_EDIT)) {
  23.         return LogUtil::registerPermissionError();
  24.     }
  25.  
  26.     // Create output object - this object will store all of our output so that
  27.     // we can return it easily when required
  28.     $pnRender pnRender::getInstance('Banners');
  29.  
  30.     // Return the output that has been generated by this function
  31.     return $pnRender->fetch('banners_admin_main.htm');
  32. }
  33.  
  34. /**
  35.  * display form to create a new banner/client
  36.  *
  37.  * @author Devin Hayes
  38.  * @return string HTML output string
  39.  */
  40. function Banners_admin_new($args)
  41. {
  42.     // Security check
  43.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_ADMIN)) {
  44.         return LogUtil::registerPermissionError();
  45.     }
  46.  
  47.     // Create output object
  48.     $pnRender pnRender::getInstance('Banners'false);
  49.  
  50.     // Check if Banners variable is active, if not then print a message
  51.     $pnRender->assign('bannersenabled'pnModGetVar('Banners''banners'));
  52.  
  53.     // get list of current clients and assign to template
  54.     $clients pnModAPIFunc('Banners''user''getallclients');
  55.     $clientitems array();
  56.     if (is_array($clients)) {
  57.         foreach($clients as $client{
  58.             $clientitems[$client['cid']] $client['name'];
  59.         }
  60.     }
  61.     $pnRender->assign('clients'$clientitems);
  62.  
  63.     // return the output
  64.     return $pnRender->fetch('banners_admin_new.htm');
  65. }
  66.  
  67. /**
  68.  * view items
  69.  *
  70.  * @author Devin Hayes
  71.  * @param int $startnum the start item id for the pager
  72.  * @return string HTML output string
  73.  */
  74. function Banners_admin_view($args)
  75. {
  76.     // Security check
  77.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_ADMIN)) {
  78.         return LogUtil::registerPermissionError();
  79.     }
  80.  
  81.     // Create output object
  82.     $pnRender pnRender::getInstance('Banners'false);
  83.  
  84.     // Check if Banners variable is active, if not then print a message
  85.     $pnRender->assign('bannersenabled'pnModGetVar('Banners''banners'));
  86.  
  87.     // get list of banners
  88.     $activebanneritems pnModAPIFunc('Banners''user''getall'array('clientinfo' => true));
  89.     $pnRender->assign('activebanneritems'$activebanneritems);
  90.  
  91.     // get list of finished banners
  92.     $finishedbanners pnModAPIFunc('Banners''user''getallfinished');
  93.     $pnRender->assign('finishedbanners'$finishedbanners);
  94.  
  95.     // get all clients
  96.     $activeclients pnModAPIFunc('Banners''user''getallclients');
  97.     $pnRender->assign('activeclients'$activeclients);
  98.  
  99.     return $pnRender->fetch('banners_admin_view.htm');
  100. }
  101.  
  102. /**
  103.  * create a banner
  104.  *
  105.  * @author Devin Hayes
  106.  * @param int $cid client id
  107.  * @param int $idtype banner type id
  108.  * @param int $imptotal total impressions purchased
  109.  * @param string $imageurl source url of the banner image
  110.  * @param string $clickurl destination url for the banner
  111.  * @return mixed int banner id if successful
  112.  */
  113. function Banners_admin_create($args)
  114. {
  115.     $banner FormUtil::getPassedValue('banner'isset($args['banner']$args['banner'null'POST');
  116.  
  117.     // Confirm authorisation code.
  118.     if (!SecurityUtil::confirmAuthKey()) {
  119.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  120.     }
  121.  
  122.     // Notable by its absence there is no security check here.
  123.     // Create the banner
  124.     $bid pnModAPIFunc('Banners''admin''create',
  125.                         array('cid'  => $banner['cid'],
  126.                               'idtype'   => $banner['idtype'],
  127.                               'imptotal' => $banner['imptotal'],
  128.                               'imageurl' => $banner['imageurl'],
  129.                               'clickurl' => $banner['clickurl']));
  130.  
  131.     // The return value of the function is checked
  132.     if ($bid != false{
  133.         // Success
  134.     }
  135.  
  136.     // This function generated no output, and so now it is complete we redirect
  137.     // the user to an appropriate page for them to carry on their work
  138.     return pnRedirect(pnModURL('Banners''admin''view'));
  139. }
  140.  
  141. /**
  142.  * modify a banner
  143.  *
  144.  * @author Devin Hayes
  145.  * @param int $args['bid'] the banner id
  146.  * @return string HTML output string
  147.  */
  148. function Banners_admin_modify($args)
  149. {
  150.     $bid FormUtil::getPassedValue('bid'isset($args['bid']$args['bid'null'GET');
  151.  
  152.     if (!is_numeric($bid)){
  153.         return LogUtil::registerError (_MODARGSERROR);
  154.     }
  155.  
  156.     // security check
  157.     if (!SecurityUtil::checkPermission('Banners::Banner'"$bid::"ACCESS_EDIT)) {
  158.         return LogUtil::registerPermissionError();
  159.     }
  160.  
  161.     // get the banner
  162.     $banner pnModAPIFunc('Banners''user''get'array('bid' => $bid));
  163.  
  164.     if ($banner == false{
  165.         return DataUtil::formatForDisplayHTML(_NOSUCHITEM);
  166.     }
  167.  
  168.     // create a new output object
  169.     $pnRender pnRender::getInstance('Banners'false);
  170.  
  171.     // assign the banner item
  172.     $pnRender->assign($banner);
  173.  
  174.     // build a list of clients suitable for html_options
  175.     $allclients pnModAPIFunc('Banners''user''getallclients');
  176.     $clients array();
  177.     foreach ($allclients as $client{
  178.         $clients[$client['cid']] $client['name'];
  179.     }
  180.     $pnRender->assign('clients'$clients);
  181.  
  182.     return $pnRender->fetch('banners_admin_banneredit.htm');
  183. }
  184.  
  185. /**
  186.  * update a banner
  187.  *
  188.  * @author Devin Hayes
  189.  * @param int $cid client id
  190.  * @param int $idtype banner type id
  191.  * @param int $imptotal total impressions purchased
  192.  * @param int $impadded additional impressions added
  193.  * @param string $imageurl source url of the banner image
  194.  * @param string $clickurl destination url for the banner
  195.  * @return bool 
  196.  */
  197. function Banners_admin_update($args)
  198. {
  199.     $banner FormUtil::getPassedValue('banner'isset($args['banner']$args['banner'null'POST');
  200.  
  201.     // Confirm authorisation code.
  202.     if (!SecurityUtil::confirmAuthKey()) {
  203.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  204.     }
  205.  
  206.     if (pnModAPIFunc('Banners''admin''update',
  207.                      array('bid' => $banner['bid'],
  208.                      'cid' => $banner['cid'],
  209.                      'idtype' => $banner['idtype'],
  210.                      'imptotal' => $banner['imptotal'],
  211.                      'impadded' => $banner['impadded'],
  212.                      'imageurl' => $banner['imageurl'],
  213.                      'clickurl' => $banner['clickurl']))){
  214.     }
  215.  
  216.     return pnRedirect(pnModURL('Banners''admin''main'));
  217. }
  218.  
  219. /**
  220.  * delete a banner
  221.  *
  222.  * @author Devin Hayes
  223.  * @param int $bid banner id
  224.  * @param int $objectid generic object id maps to bid if present
  225.  * @param bool $confirmation confirmation of the deletion
  226.  * @return mixed HTML output string if no confirmation, true if succesful, false otherwise
  227.  */
  228. function Banners_admin_delete($args)
  229. {
  230.     $bid          = (int)FormUtil::getPassedValue('bid'isset($args['bid']$args['bid'null'REQUEST');
  231.     $objectid     = (int)FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  232.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  233.     if ($objectid{
  234.         $bid $objectid;
  235.     }
  236.  
  237.     // Get the existing admin message
  238.     $banner pnModAPIFunc('Banners''user''get'array('bid' => $bid'clientinfo' => true));
  239.     if ($banner == false{
  240.         return DataUtil::formatForDisplayHTML(_NOSUCHITEM);
  241.     }
  242.  
  243.     // Security check
  244.     if (!SecurityUtil::checkPermission('Banners::'"$bid::"ACCESS_DELETE)) {
  245.         return LogUtil::registerPermissionError();
  246.     }
  247.  
  248.     // Check for confirmation.
  249.     if (empty($confirmation)) {
  250.         // No confirmation yet
  251.         // Create output object
  252.         $pnRender pnRender::getInstance('Banners'false);
  253.  
  254.         // Add the message id
  255.         $pnRender->assign('bid'$bid);
  256.  
  257.         // assign the full item
  258.         $pnRender->assign($banner);
  259.  
  260.         // Return the output that has been generated by this function
  261.         return $pnRender->fetch('banners_admin_bannerdelete.htm');
  262.     }
  263.  
  264.     // Confirm authorisation code.
  265.     if (!SecurityUtil::confirmAuthKey()) {
  266.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  267.     }
  268.  
  269.     // Delete the banner
  270.     // The return value of the function is checked
  271.     if (pnModAPIFunc('Banners''admin''delete'array('bid' => $bid))) {
  272.         // Success
  273.     }
  274.  
  275.     // This function generated no output, and so now it is complete we redirect
  276.     // the user to an appropriate page for them to carry on their work
  277.     return pnRedirect(pnModURL('Banners''admin''view'));
  278. }
  279.  
  280. /**************************** client functions ****************************/
  281.  
  282. /**
  283.  * create a client
  284.  *
  285.  * @author Devin Hayes
  286.  * @param int $cname client name
  287.  * @param int $contact client contact name
  288.  * @param int $email client e-mail address
  289.  * @param string $login client login name
  290.  * @param string $passwd client login password
  291.  * @param string $extrainfo additional client information
  292.  * @return mixed int banner id if successful
  293.  */
  294. {
  295.     $client FormUtil::getPassedValue('client'isset($args['client']$args['client'null'POST');
  296.  
  297.     // Confirm authorisation code.
  298.     if (!SecurityUtil::confirmAuthKey()) {
  299.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  300.     }
  301.  
  302.     if (pnModAPIFunc('Banners''admin''createclient',
  303.                     array('cname' => $client['cname'],
  304.                           'contact' => $client['contact'],
  305.                           'email' => $client['email'],
  306.                           'login' => $client['login'],
  307.                           'passwd' => $client['passwd'],
  308.                           'extrainfo' => $client['extrainfo']))){
  309.     }
  310.  
  311.     return pnRedirect(pnModURL('Banners''admin''main'));
  312. }
  313.  
  314. /**
  315.  * modify a banner client
  316.  *
  317.  * @author Devin Hayes
  318.  * @param int $cid the client id
  319.  * @return string HTML output string
  320.  */
  321. {
  322.     $cid FormUtil::getPassedValue('cid'isset($args['cid']$args['cid'null'GET');
  323.  
  324.     if (!is_numeric($cid)){
  325.         return LogUtil::registerError (_MODARGSERROR);
  326.     }
  327.  
  328.     // security check
  329.     if (!SecurityUtil::checkPermission('Banners::Client'"$cid::"ACCESS_EDIT)) {
  330.         return LogUtil::registerPermissionError();
  331.     }
  332.  
  333.     // get the banner
  334.     $client pnModAPIFunc('Banners''user''getclient'array('cid' => $cid));
  335.  
  336.     if ($client == false{
  337.         return DataUtil::formatForDisplayHTML(_NOSUCHITEM);
  338.     }
  339.  
  340.     // create a new output object
  341.     $pnRender pnRender::getInstance('Banners'false);
  342.  
  343.     // assign the banner item
  344.     $pnRender->assign($client);
  345.  
  346.     return $pnRender->fetch('banners_admin_clientedit.htm');
  347. }
  348.  
  349. /**
  350.  * update a banner client
  351.  *
  352.  * @author Devin Hayes
  353.  * @param int $cid client id
  354.  * @param int $cname client name
  355.  * @param int $contact client contact name
  356.  * @param int $email client e-mail address
  357.  * @param string $login client login name
  358.  * @param string $passwd client login password
  359.  * @param string $extrainfo additional client information
  360.  * @return bool 
  361.  */
  362. {
  363.     $client FormUtil::getPassedValue('client'isset($args['client']$args['client'null'POST');
  364.  
  365.     // Confirm authorisation code.
  366.     if (!SecurityUtil::confirmAuthKey()) {
  367.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  368.     }
  369.  
  370.     if (pnModAPIFunc('Banners''admin''updateclient',
  371.                      array('cid' => $client['cid'],
  372.                            'cname' => $client['cname'],
  373.                            'contact' => $client['contact'],
  374.                            'email' => $client['email'],
  375.                            'extrainfo' => $client['extrainfo'],
  376.                            'login' => $client['login'],
  377.                            'passwd' => $client['passwd']))){
  378.     }
  379.  
  380.     return pnRedirect(pnModURL('Banners''admin''main'));
  381. }
  382.  
  383. /**
  384.  * delete a banner
  385.  *
  386.  * @author Devin Hayes
  387.  * @param int $cid client id
  388.  * @param int $objectid generic object id maps to bid if present
  389.  * @param bool $confirmation confirmation of the deletion
  390.  * @return mixed HTML output string if no confirmation, true if succesful, false otherwise
  391.  */
  392. {
  393.     $cid FormUtil::getPassedValue('cid'isset($args['cid']$args['cid'null'REQUEST');
  394.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  395.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  396.     if (!empty($objectid)) {
  397.         $cid $objectid;
  398.     }
  399.  
  400.     // Get the existing admin message
  401.     $client pnModAPIFunc('Banners''user''getclient'array('cid' => $cid));
  402.  
  403.     if ($client == false{
  404.         return DataUtil::formatForDisplayHTML(_NOSUCHITEM);
  405.     }
  406.  
  407.     // Security check
  408.     if (!SecurityUtil::checkPermission('Banners::Client'"$cid::"ACCESS_DELETE)) {
  409.         return LogUtil::registerPermissionError();
  410.     }
  411.  
  412.     // Check for confirmation.
  413.     if (empty($confirmation)) {
  414.         // No confirmation yet
  415.         // Create output object
  416.         $pnRender pnRender::getInstance('Banners'false);
  417.  
  418.         // Add the message id
  419.         $pnRender->assign('cid'$cid);
  420.  
  421.         // assign the full item
  422.         $pnRender->assign('banners'pnModAPIFunc('Banners''user''getall'array('cid' => $cid)));
  423.  
  424.         // Return the output that has been generated by this function
  425.         return $pnRender->fetch('banners_admin_clientdelete.htm');
  426.     }
  427.  
  428.     // Confirm authorisation code.
  429.     if (!SecurityUtil::confirmAuthKey()) {
  430.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  431.     }
  432.  
  433.     // Delete the banner
  434.     // The return value of the function is checked
  435.     if (pnModAPIFunc('Banners''admin''deleteclient'array('cid' => $cid))) {
  436.         // Success
  437.     }
  438.  
  439.     // This function generated no output, and so now it is complete we redirect
  440.     // the user to an appropriate page for them to carry on their work
  441.     return pnRedirect(pnModURL('Banners''admin''view'));
  442. }
  443.  
  444. /**************************** finished banner functions ****************************/
  445.  
  446. /**
  447.  * delete a finished banner
  448.  *
  449.  * @author Devin Hayes
  450.  * @param int $bid banner id
  451.  * @param int $objectid generic object id maps to bid if present
  452.  * @param bool $confirmation confirmation of the deletion
  453.  * @return mixed HTML output string if no confirmation, true if succesful, false otherwise
  454.  */
  455. {
  456.     $bid FormUtil::getPassedValue('bid'isset($args['bid']$args['bid'null'REQUEST');
  457.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  458.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  459.     if (!empty($objectid)) {
  460.         $bid $objectid;
  461.     }
  462.  
  463.     // Get the existing admin message
  464.     $banner pnModAPIFunc('Banners''user''get'array('bid' => $bid));
  465.  
  466.     if ($banner == false{
  467.         return DataUtil::formatForDisplayHTML(_NOSUCHITEM);
  468.     }
  469.  
  470.     // Security check
  471.     if (!SecurityUtil::checkPermission('Banners::'"$bid::"ACCESS_DELETE)) {
  472.         return LogUtil::registerPermissionError();
  473.     }
  474.  
  475.     // Check for confirmation.
  476.     if (empty($confirmation)) {
  477.         // No confirmation yet
  478.         // Create output object
  479.         $pnRender pnRender::getInstance('Banners'false);
  480.  
  481.         // Add the message id
  482.         $pnRender->assign('bid'$bid);
  483.  
  484.         // assign the full item
  485.         $pnRender->assign(pnModAPIFunc('Banners''user''getfinished'array('bid' => $bid)));
  486.  
  487.         // Return the output that has been generated by this function
  488.         return $pnRender->fetch('banners_admin_bannerdelete.htm');
  489.     }
  490.  
  491.     // Confirm authorisation code.
  492.     if (!SecurityUtil::confirmAuthKey()) {
  493.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  494.     }
  495.  
  496.     // Delete the banner
  497.     // The return value of the function is checked
  498.     if (pnModAPIFunc('Banners''admin''deletefinished'array('bid' => $bid))) {
  499.         // Success
  500.     }
  501.  
  502.     // This function generated no output, and so now it is complete we redirect
  503.     // the user to an appropriate page for them to carry on their work
  504.     return pnRedirect(pnModURL('Banners''admin''view'));
  505. }
  506.  
  507. /**************************** configuration functions ****************************/
  508.  
  509. /**
  510.  * This is a standard function to modify the configuration parameters of the
  511.  * module
  512.  *
  513.  * @author Devin Hayes
  514.  * @return string HTML output string
  515.  */
  516. {
  517.     // Security check
  518.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_ADMIN)) {
  519.         return LogUtil::registerPermissionError();
  520.     }
  521.  
  522.     // Create output object
  523.     $pnRender pnRender::getInstance('Banners'false);
  524.  
  525.     // Number of items to display per page
  526.     $pnRender->assign(pnModGetVar('Banners'));
  527.  
  528.     // Return the output that has been generated by this function
  529.     return $pnRender->fetch('banners_admin_modifyconfig.htm');
  530. }
  531.  
  532. /**
  533.  * This is a standard function to update the configuration parameters of the
  534.  * module given the information passed back by the modification form
  535.  *
  536.  * @author Devin Hayes
  537.  * @param int $itemsperpage the number messages per page in the admin panel
  538.  * @return bool true if successful, false otherwise
  539.  */
  540. {
  541.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_ADMIN)) {
  542.         return LogUtil::registerPermissionError();
  543.     }
  544.  
  545.     $banners         FormUtil::getPassedValue('banners'null'POST');
  546.     $myIP            FormUtil::getPassedValue('myIP'null'POST');
  547.     $openinnewwindow FormUtil::getPassedValue('openinnewwindow'null'POST');
  548.  
  549.     // Confirm authorisation code.
  550.     if (!SecurityUtil::confirmAuthKey()) {
  551.         return LogUtil::registerAuthidError (pnModURL('Banners''admin''view'));
  552.     }
  553.  
  554.     // Update module variables.
  555.     pnModSetVar('Banners''banners'$banners);
  556.     pnModSetVar('Banners''myIP'$myIP);
  557.     pnModSetVar('Banners''openinnewwindow'$openinnewwindow);
  558.  
  559.     // Let any other modules know that the modules configuration has been updated
  560.     pnModCallHooks('module','updateconfig','Banners'array('module' => 'Banners'));
  561.  
  562.     // the module configuration has been updated successfuly
  563.  
  564.     // This function generated no output, and so now it is complete we redirect
  565.     // the user to an appropriate page for them to carry on their work
  566.     return pnRedirect(pnModURL('Banners''admin''view'));
  567. }

Documentation generated on Fri, 18 Jul 2008 21:50:00 +0200 by phpDocumentor 1.4.1