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

Source for file pnadminapi.php

Documentation is available at pnadminapi.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: pnadminapi.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.  * create a banner
  15.  *
  16.  * @author Devin Hayes
  17.  * @param int $cid client id
  18.  * @param int $idtype banner type id
  19.  * @param int $imptotal total impressions purchased
  20.  * @param string $imageurl source url of the banner image
  21.  * @param string $clickurl destination url for the banner
  22.  * @return string HTML output string
  23.  */
  24. function Banners_adminapi_create($args)
  25. {
  26.     // Argument check
  27.     if (!isset($args['cid']||
  28.         !isset($args['idtype']||
  29.         !isset($args['imptotal']||
  30.         !isset($args['imageurl']||
  31.         !isset($args['clickurl'])) {
  32.         return LogUtil::registerError (_MODARGSERROR);
  33.     }
  34.  
  35.     // Security check
  36.     if (!SecurityUtil::checkPermission('Banners::''::'ACCESS_ADD)) {
  37.         return LogUtil::registerPermissionError();
  38.     }
  39.  
  40.     // create the item array
  41.     $banner array('cid' => $args['cid'],
  42.                     'type' => $args['idtype'],
  43.                     'imptotal' => $args['imptotal'],
  44.                     'imageurl' => $args['imageurl'],
  45.                     'clickurl' => $args['clickurl']);
  46.  
  47.     if (!DBUtil::insertObject($banner'banners''bid')) {
  48.         return LogUtil::registerError (_CREATEFAILED);
  49.     }
  50.  
  51.     // Return the id of the newly created item to the calling process
  52.     return $banner['bid'];
  53. }
  54.  
  55. /**
  56.  * update a banner
  57.  *
  58.  * @author Devin Hayes
  59.  * @param int $bid banner id
  60.  * @param int $cid client id
  61.  * @param int $idtype banner type id
  62.  * @param int $impadded additional impressions purchased
  63.  * @param int $imptotal total impressions purchased
  64.  * @param string $imageurl source url of the banner image
  65.  * @param string $clickurl destination url for the banner
  66.  * @return string HTML output string
  67.  */
  68. function Banners_adminapi_update($args)
  69. {
  70.     // Argument check
  71.     if (!isset($args['bid']||
  72.         !isset($args['cid']||
  73.         !isset($args['idtype']||
  74.         !isset($args['imptotal']||
  75.         !isset($args['impadded']||
  76.         !isset($args['imageurl']||
  77.         !isset($args['clickurl'])) {
  78.         return LogUtil::registerError (_MODARGSERROR);
  79.     }
  80.  
  81.     // Get the existing admin message
  82.     $banner pnModAPIFunc('Banners''user''get'array('bid' => $args['bid']));
  83.  
  84.     if ($banner == false{
  85.         return LogUtil::registerError (_NOSUCHITEM);
  86.     }
  87.  
  88.     // Security check
  89.     if (!SecurityUtil::checkPermission('Banners::'"$bid::"ACCESS_EDIT)) {
  90.         return LogUtil::registerPermissionError();
  91.     }
  92.  
  93.     // create the item array
  94.     $banner array('bid' => $args['bid'],
  95.                     'cid' => $args['cid'],
  96.                     'type' => $args['idtype'],
  97.                     'imptotal' => $args['imptotal'],
  98.                     'imageurl' => $args['imageurl'],
  99.                     'clickurl' => $args['clickurl']);
  100.     $banner['imptotal'+= $args['impadded'];
  101.  
  102.     if (!DBUtil::updateObject($banner'banners''''bid')) {
  103.         return LogUtil::registerError (_UPDATEFAILED);
  104.     }
  105.  
  106.     return true;
  107. }
  108.  
  109. /**
  110.  * delete a banner
  111.  *
  112.  * @author Devin Hayes
  113.  * @param int $bid banner id
  114.  * @return bool true on success, false on failure
  115.  */
  116. function Banners_adminapi_delete($args)
  117. {
  118.     // Argument check
  119.     if (!isset($args['bid'])) {
  120.         return LogUtil::registerError (_MODARGSERROR);
  121.     }
  122.  
  123.     // Get the existing admin message
  124.     $banner pnModAPIFunc('Banners''user''get'array('bid' => $args['bid']));
  125.  
  126.     if ($banner == false{
  127.         return LogUtil::registerError (_NOSUCHITEM);
  128.     }
  129.  
  130.     // Security check
  131.     if (!SecurityUtil::checkPermission('Banners::'"$args[bid]::"ACCESS_DELETE)) {
  132.         return LogUtil::registerPermissionError();
  133.     }
  134.  
  135.     if (!DBUtil::deleteObjectByID('banners'$args['bid']'bid')) {
  136.         return LogUtil::registerError (_DELETEFAILED);
  137.     }
  138.  
  139.     // Let the calling process know that we have finished successfully
  140.     return true;
  141. }
  142.  
  143. /**
  144.  * delete all banners for a client
  145.  *
  146.  * @author Devin Hayes
  147.  * @param int $cid client id
  148.  * @return bool true on success, false on failure
  149.  */
  150. {
  151.     // Argument check
  152.     if (!isset($args['cid'])) {
  153.         return LogUtil::registerError (_MODARGSERROR);
  154.     }
  155.  
  156.     // Security check
  157.     if (!SecurityUtil::checkPermission('Banners::Client'"$args[cid]::"ACCESS_DELETE)) {
  158.         return LogUtil::registerPermissionError();
  159.     }
  160.  
  161.     if (!DBUtil::deleteObjectByID('banners'$args['cid']'cid')) {
  162.         return LogUtil::registerError (_DELETEFAILED);
  163.     }
  164.  
  165.     // Let the calling process know that we have finished successfully
  166.     return true;
  167. }
  168.  
  169. /********************* client functions *************************/
  170.  
  171. /**
  172.  * create a client
  173.  *
  174.  * @author Devin Hayes
  175.  * @param int $cname client name
  176.  * @param int $contact client contact name
  177.  * @param int $email client contact e-mail
  178.  * @param string $login client login name
  179.  * @param string $password client login password
  180.  * @param string $extrainfo additional client info
  181.  * @return mixed int client id if successful, false otherwise
  182.  */
  183. {
  184.     // Argument check
  185.     if (!isset($args['cname']||
  186.         !isset($args['contact']||
  187.         !isset($args['email']||
  188.         !isset($args['login']||
  189.         !isset($args['passwd']||
  190.         !isset($args['extrainfo'])) {
  191.         return LogUtil::registerError (_MODARGSERROR);
  192.     }
  193.  
  194.     // Security check
  195.     if (!SecurityUtil::checkPermission('Banners::Client''::'ACCESS_ADD)) {
  196.         return LogUtil::registerPermissionError();
  197.     }
  198.  
  199.     // create the item array
  200.     $client array('name' => $args['cname'],
  201.                     'contact' => $args['contact'],
  202.                     'email' => $args['email'],
  203.                     'login' => $args['login'],
  204.                     'passwd' => $args['passwd'],
  205.                     'extrainfo' => $args['extrainfo']);
  206.  
  207.     if (!DBUtil::insertObject($client'bannersclient''cid')) {
  208.         return LogUtil::registerError (_CREATEFAILED);
  209.     }
  210.  
  211.     // Return the id of the newly created item to the calling process
  212.     return $client['cid'];
  213. }
  214.  
  215. /**
  216.  * update a banner
  217.  *
  218.  * @author Devin Hayes
  219.  * @param int $cid client id
  220.  * @param int $cname client name
  221.  * @param int $contact client contact name
  222.  * @param int $email client contact e-mail
  223.  * @param string $login client login name
  224.  * @param string $password client login password
  225.  * @param string $extrainfo additional client info
  226.  * @return bool true if successful, false otherwise
  227.  */
  228. {
  229.     // Argument check
  230.     if (!isset($args['cid']||
  231.         !isset($args['cname']||
  232.         !isset($args['contact']||
  233.         !isset($args['email']||
  234.         !isset($args['login']||
  235.         !isset($args['passwd']||
  236.         !isset($args['extrainfo'])) {
  237.         return LogUtil::registerError (_MODARGSERROR);
  238.     }
  239.  
  240.     // Get the existing admin message
  241.     $client pnModAPIFunc('Banners''user''getclient'array('cid' => $args['cid']));
  242.  
  243.     if ($client == false{
  244.         return LogUtil::registerError (_NOSUCHITEM);
  245.     }
  246.  
  247.     // Security check
  248.     if (!SecurityUtil::checkPermission('Banners::Client'"$args[cid]::"ACCESS_EDIT)) {
  249.         return LogUtil::registerPermissionError();
  250.     }
  251.  
  252.     // create the new item array
  253.     $client array('cid' => $args['cid'],
  254.                     'name' => $args['cname'],
  255.                     'contact' => $args['contact'],
  256.                     'email' => $args['email'],
  257.                     'login' => $args['login'],
  258.                     'passwd' => $args['passwd'],
  259.                     'extrainfo' => $args['extrainfo']);
  260.  
  261.     if (!DBUtil::updateObject($client'bannersclient''''cid')) {
  262.         return LogUtil::registerError (_UPDATEFAILED);
  263.     }
  264.  
  265.     return true;
  266. }
  267.  
  268. /**
  269.  * delete a client
  270.  *
  271.  * @author Devin Hayes
  272.  * @param int $cid client id
  273.  * @return bool true on success, false on failure
  274.  */
  275. {
  276.     // Argument check
  277.     if (!isset($args['cid'])) {
  278.         return LogUtil::registerError (_MODARGSERROR);
  279.     }
  280.  
  281.     // Get the existing admin message
  282.     $client pnModAPIFunc('Banners''user''getclient'array('cid' => $args['cid']));
  283.  
  284.     if ($client == false{
  285.         return LogUtil::registerError (_NOSUCHITEM);
  286.     }
  287.  
  288.     // Security check
  289.     if (!SecurityUtil::checkPermission('Banners::Client'"$args[cid]::"ACCESS_DELETE)) {
  290.         return LogUtil::registerPermissionError();
  291.     }
  292.  
  293.     // delete any banners for this client first
  294.     if (!pnModAPIFunc('Banners''admin''deleteall'array('cid' => $args['cid']))) {
  295.         return LogUtil::registerError (_DELETEFAILED);
  296.     }
  297.  
  298.     // now delete the client
  299.     if (!DBUtil::deleteObjectByID('bannersclient'$args['cid']'cid')) {
  300.         return LogUtil::registerError (_DELETEFAILED);
  301.     }
  302.  
  303.     // Let the calling process know that we have finished successfully
  304.     return true;
  305. }
  306.  
  307. /******************* finished banners functions ************************/
  308.  
  309. /**
  310.  * delete a finished banner
  311.  *
  312.  * @author Devin Hayes
  313.  * @param int $bid banner id
  314.  * @return bool true on success, false on failure
  315.  */
  316. {
  317.     // Argument check
  318.     if (!isset($args['bid'])) {
  319.         return LogUtil::registerError (_MODARGSERROR);
  320.     }
  321.  
  322.     // Get the existing admin message
  323.     $banner pnModAPIFunc('Banners''user''getfinished'array('bid' => $args['bid']));
  324.  
  325.     if ($banner == false{
  326.         return LogUtil::registerError (_NOSUCHITEM);
  327.     }
  328.  
  329.     // Security check
  330.     if (!SecurityUtil::checkPermission('Banners::'"$args[bid]::"ACCESS_DELETE)) {
  331.         return LogUtil::registerPermissionError();
  332.     }
  333.  
  334.     if (!DBUtil::deleteObjectByID('bannersfinished'$args['bid']'bid')) {
  335.         return LogUtil::registerError (_DELETEFAILED);
  336.     }
  337.  
  338.     // Let the calling process know that we have finished successfully
  339.     return true;
  340. }
  341.  
  342. /**
  343.  * get available admin panel links
  344.  *
  345.  * @author Mark West
  346.  * @return array array of admin links
  347.  */
  348. {
  349.     $links array();
  350.  
  351.     pnModLangLoad('Banners''admin');
  352.  
  353.     if (SecurityUtil::checkPermission('Banners::''::'ACCESS_READ)) {
  354.         $links[array('url' => pnModURL('Banners''admin''view')'text' => _BANNERS_VIEW);
  355.     }
  356.     if (SecurityUtil::checkPermission('Banners::''::'ACCESS_ADD)) {
  357.         $links[array('url' => pnModURL('Banners''admin''new')'text' => _BANNERS_ADD);
  358.     }
  359.     if (SecurityUtil::checkPermission('Banners::''::'ACCESS_ADMIN)) {
  360.         $links[array('url' => pnModURL('Banners''admin''modifyconfig')'text' => _MODIFYCONFIG);
  361.     }
  362.  
  363.     return $links;
  364. }

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