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 MailUsers
  11.  */
  12.  
  13. /**
  14.  * the main administration function
  15.  *
  16.  * This function is the default function, and is called whenever the
  17.  * module is called without defining arguments.
  18.  * As such it can be used for a number of things, but most commonly
  19.  * it either just shows the module menu and returns or calls whatever
  20.  * the module designer feels should be the default function (often this
  21.  * is the view() function)
  22.  *
  23.  * @author       Xiaoyu Huang
  24.  * @return       output       The main module admin page.
  25.  */
  26. {
  27.     // Security check - important to do this as early as possible to avoid
  28.     // potential security holes or just too much wasted processing
  29.     if (!SecurityUtil::checkPermission('MailUsers::''::'ACCESS_ADMIN)) {
  30.         return LogUtil::registerPermissionError();
  31.     }
  32.  
  33.     return pnRedirect(pnModURL('mailusers','admin','view'));
  34. }
  35.  
  36. /**
  37.  * Display main form
  38.  *
  39.  * This function shows a form to send an e-mail
  40.  *
  41.  * @author       Xiaoyu Huang
  42.  * @return       output       The main module admin page
  43.  */
  44. function mailusers_admin_view($args)
  45. {
  46.     // Security check - important to do this as early as possible to avoid
  47.     // potential security holes or just too much wasted processing
  48.     if (!SecurityUtil::checkPermission('MailUsers::''::'ACCESS_ADMIN)) {
  49.         return LogUtil::registerPermissionError();
  50.     }
  51.  
  52.     // Get parameters from whatever input we need.  All arguments to this
  53.     // function should be obtained from FormUtil::getPassedValue(), getting them
  54.     // from other places such as the environment is not allowed, as that makes
  55.     // assumptions that will not hold in future versions of Zikula
  56.     $userid = (int)FormUtil::getPassedValue('userid'null'REQUEST');
  57.  
  58.     // Admin functions of this type can be called by other modules.  If this
  59.     // happens then the calling module will be able to pass in arguments to
  60.     // this function through the $args parameter.  Hence we extract these
  61.     // arguments *after* we have obtained any form-based input through
  62.     // FormUtil::getPassedValue().
  63.     extract($args);
  64.  
  65.     // get the groups from the groups API and process into
  66.     // a form useful for the html_options smarty plugin
  67.     $groups array();
  68.     if (pnModAvailable('Groups')) {
  69.         $groupsapi pnModAPIFunc('Groups''user''getall');
  70.         foreach ($groupsapi as $group{
  71.             $groups[$group['gid']] $group['name'];
  72.         }
  73.     }
  74.  
  75.     // Create output object - this object will store all of our output so that
  76.     // we can return it easily when required
  77.     $pnRender pnRender::getInstance('MailUsers');
  78.  
  79.     // As Admin output changes often, we do not want caching.
  80.     $pnRender->caching false;
  81.  
  82.     // if we have user id from the input then assign the username
  83.     if (isset($userid&& is_numeric($userid)) {
  84.         $pnRender->assign('uname'pnUserGetVar('uname'$userid));
  85.     }
  86.  
  87.     $pnRender->assign('groups'$groups);
  88.  
  89.     // Return the output
  90.     return $pnRender->fetch('mailusers_admin_view.htm');
  91.  
  92. }
  93.  
  94. /**
  95.  * Send e-mails
  96.  *
  97.  * This function shows a form to send an e-mail
  98.  *
  99.  * @author       Xiaoyu Huang
  100.  * @todo         Move groups table sql to groups API
  101.  * @todo         Move users table sql to users API
  102.  * @return       output       The main module admin page
  103.  */
  104. {
  105.     // Security check - important to do this as early as possible to avoid
  106.     // potential security holes or just too much wasted processing
  107.     if (!SecurityUtil::checkPermission('MailUsers::''::'ACCESS_ADMIN)) {
  108.         return LogUtil::registerPermissionError();
  109.     }
  110.  
  111.     // Get parameters from whatever input we need.  All arguments to this
  112.     // function should be obtained from FormUtil::getPassedValue(), getting them
  113.     // from other places such as the environment is not allowed, as that makes
  114.     // assumptions that will not hold in future versions of Zikula
  115.     $from          FormUtil::getPassedValue('from'null'REQUEST');
  116.     $rpemail       FormUtil::getPassedValue('rpemail'null'REQUEST');
  117.     $subject       FormUtil::getPassedValue('subject'null'REQUEST');
  118.     $message       FormUtil::getPassedValue('message'null'REQUEST');
  119.     $uname         FormUtil::getPassedValue('uname'null'REQUEST');
  120.     $unamecontains FormUtil::getPassedValue('unamecontains'null'REQUEST');
  121.     $rname         FormUtil::getPassedValue('rname'null'REQUEST');
  122.     $ugroup        FormUtil::getPassedValue('ugroup'null'REQUEST');
  123.     $email         FormUtil::getPassedValue('email'null'REQUEST');
  124.     $homepage      FormUtil::getPassedValue('homepage'null'REQUEST');
  125.     $icq           FormUtil::getPassedValue('icq'null'REQUEST');
  126.     $msn           FormUtil::getPassedValue('msn'null'REQUEST');
  127.     $aim           FormUtil::getPassedValue('aim'null'REQUEST');
  128.     $yim           FormUtil::getPassedValue('yim'null'REQUEST');
  129.     $signature     FormUtil::getPassedValue('signature'null'REQUEST');
  130.     $regdateafter  FormUtil::getPassedValue('regdateafter'null'REQUEST');
  131.     $regdatebefore FormUtil::getPassedValue('regdatebefore'null'REQUEST');
  132.     $testonly      FormUtil::getPassedValue('testonly'null'REQUEST');
  133.     $perpage       FormUtil::getPassedValue('perpage'null'REQUEST');
  134.     $page          FormUtil::getPassedValue('page'null'REQUEST');
  135.     $totalpages    FormUtil::getPassedValue('totalpages'null'REQUEST');
  136.     $startat       FormUtil::getPassedValue('startat'null'REQUEST');
  137.     $output        FormUtil::getPassedValue('output'null'REQUEST');
  138.  
  139.     if ($from == ''{
  140.         return _NM_ERROR2;
  141.     elseif (!pnVarValidate($rpemail,'email')) {
  142.         return _NM_ERROR3;
  143.     elseif ($subject == ""{
  144.         return _NM_ERROR4;
  145.     elseif ($message == ""{
  146.         return _NM_ERROR5;
  147.     }
  148.  
  149.  
  150.     if (isset($perpage)==or $perpage==""{
  151.         $perpage=500;
  152.     }
  153.     if (isset($startat)==or $startat==""{
  154.         $startat=0;
  155.     }
  156.  
  157.     $pntable pnDBGetTables();
  158.     $column  $pntable['users_column'];
  159.  
  160.     if (!isset($condition|| $condition == ''{
  161.         $condition '1=1';
  162.  
  163.         if ($uname != ''{
  164.             $condition .= " AND ".$column['uname']." = '".DataUtil::formatForStore($uname)."'";
  165.         }
  166.         if ($unamecontains != ''{
  167.             $condition .= " AND INSTR(".$column['uname'].",'".DataUtil::formatForStore($unamecontains)."')>0";
  168.         }
  169.         if ($rname != ''{
  170.             $condition .= " AND INSTR(".$column['name'].",'".DataUtil::formatForStore($rname)."')>0";
  171.         }
  172.     if ($ugroup != 0{
  173.             $uids DBUtil::selectFieldArrayByID ('group_membership''uid'$ugroup'gid');
  174.             $condition .= " AND (";
  175.         foreach ($uids as $uid{
  176.                 $condition.="".$column['uid']."='".DataUtil::formatForStore($uid)."' OR ";
  177.             }
  178.             $condition .= '0)';
  179.         }
  180.         if ($email != ''{
  181.             $condition .= " AND INSTR(".$column['email'].",'".DataUtil::formatForStore($email)."')>0";
  182.         }
  183.         if ($homepage != ''{
  184.             $condition .= " AND INSTR(".$column['url'].",'".DataUtil::formatForStore($homepage)."')>0";
  185.         }
  186.         if ($icq != ''{
  187.             $condition .= " AND INSTR(".$column['user_icq'].",'".DataUtil::formatForStore($icq)."')>0";
  188.         }
  189.         if ($msn != ''{
  190.             $condition .= " AND INSTR(".$column['user_msnm'].",'".DataUtil::formatForStore($msn)."')>0";
  191.         }
  192.         if ($aim != ''{
  193.             $condition .= " AND INSTR(".$column['user_aim'].",'".DataUtil::formatForStore($aim)."')>0";
  194.         }
  195.         if ($yim != ''{
  196.             $condition .= " AND INSTR(".$column['user_yim'].",'".DataUtil::formatForStore($yim)."')>0";
  197.         }
  198.         if ($signature != ''{
  199.             $condition .= " AND INSTR(".$column['user_sig'].",'".DataUtil::formatForStore($signature)."')>0";
  200.         }
  201.         if ($regdateafter != ''{
  202.             $condition .= " AND ".$column['user_regdate'].">UNIX_TIMESTAMP('".DataUtil::formatForStore($regdateafter)."')";
  203.         }
  204.         if ($regdatebefore != ''{
  205.             $condition .= " AND ".$column['user_regdate']."<UNIX_TIMESTAMP('".DataUtil::formatForStore($regdatebefore)."')";
  206.         }
  207.     }
  208.  
  209.     $where $condition " AND " $column['uname']."!='Anonymous'";
  210.     $count DBUtil::selectObjectCount ('users'$where);
  211.     if ($count == 0{
  212.         return _NM_NOMATCHUSER;
  213.     else {
  214.         $sort 'uid';
  215.         $users DBUtil::selectObjectArray ('users'$where$sort$startat$perpage);
  216.         if ($users{
  217.             $page $startat/$perpage+1;
  218.             $totalpages ceil($count/$perpage);
  219.             $output _NM_SENDING._NM_PAGE1.$page._NM_PAGE2.$totalpages._NM_PAGE3.$count._NM_USERS."<br />";
  220.  
  221.             foreach ($users as $userinfo{
  222.                 if ($testonly == 1{
  223.                     $output .= _NM_TESTING.$userinfo['uname']." "._NM_EMAIL.$userinfo['email']."<br />";
  224.                 else {
  225.                     pnMail($rpemail$subject$message"From: \"".$from."\" <".$rpemail.">\nBcc: ".$userinfo['email']."\nX-Mailer: PHP/" phpversion());
  226.                     $output .= _NM_SENDING.$userinfo['uname']." "._NM_EMAIL.$userinfo['email']."<br />";
  227.                 }
  228.             }
  229.             $modname pnModGetName();
  230.  
  231.             pnModDelVar($modname'from');
  232.             pnModDelVar($modname'rpemail');
  233.             pnModDelVar($modname'subject');
  234.             pnModDelVar($modname'message');
  235.             pnModDelVar($modname'uname');
  236.             pnModDelVar($modname'rname');
  237.             pnModDelVar($modname'ugroup');
  238.             pnModDelVar($modname'email');
  239.             pnModDelVar($modname'homepage');
  240.             pnModDelVar($modname'icq');
  241.             pnModDelVar($modname'msn');
  242.             pnModDelVar($modname'aim');
  243.             pnModDelVar($modname'yim');
  244.             pnModDelVar($modname'signature');
  245.             pnModDelVar($modname'regdateafter');
  246.             pnModDelVar($modname'regdatebefore');
  247.             pnModDelVar($modname'testonly');
  248.             pnModDelVar($modname'perpage');
  249.             pnModDelVar($modname'page');
  250.             pnModDelVar($modname'totalpages');
  251.             pnModDelVar($modname'startat');
  252.             pnModDelVar($modname'output');
  253.  
  254.             pnModSetVar($modname'from'$from);
  255.             pnModSetVar($modname'rpemail'$rpemail);
  256.             pnModSetVar($modname'subject'$subject);
  257.             pnModSetVar($modname'message'$message);
  258.             pnModSetVar($modname'uname'$uname);
  259.             pnModSetVar($modname'rname'$rname);
  260.             pnModSetVar($modname'ugroup'$ugroup);
  261.             pnModSetVar($modname'email'$email);
  262.             pnModSetVar($modname'homepage'$homepage);
  263.             pnModSetVar($modname'icq'$icq);
  264.             pnModSetVar($modname'msn'$msn);
  265.             pnModSetVar($modname'aim'$aim);
  266.             pnModSetVar($modname'yim'$yim);
  267.             pnModSetVar($modname'signature'$signature);
  268.             pnModSetVar($modname'regdateafter'$regdateafter);
  269.             pnModSetVar($modname'regdatebefore'$regdatebefore);
  270.             pnModSetVar($modname'testonly'$testonly);
  271.             pnModSetVar($modname'perpage'$perpage);
  272.             pnModSetVar($modname'page'$page);
  273.             pnModSetVar($modname'totalpages'$totalpages);
  274.             pnModSetVar($modname'startat'$startat);
  275.             pnModSetVar($modname'output'$output);
  276.  
  277.             pnRedirect(pnModURL('mailusers','admin','sendnext'));
  278.  
  279.         else {
  280.             $output .= _NM_FINISH;
  281.         }
  282.     }
  283.     return $output;
  284. }
  285.  
  286.  
  287. /**
  288.  * Display form to continue sending mail
  289.  *
  290.  * This function shows a form to continue send the e-mail
  291.  * when a bulk mail is split to ensure process completes
  292.  *
  293.  * @author       Xiaoyu Huang
  294.  * @todo         template output
  295.  * @return       output       The main module admin page
  296.  */
  297. {
  298.     // Security check - important to do this as early as possible to avoid
  299.     // potential security holes or just too much wasted processing
  300.     if (!SecurityUtil::checkPermission('MailUsers::''::'ACCESS_ADMIN)) {
  301.         return LogUtil::registerPermissionError();
  302.     }
  303.  
  304.     $modname pnModGetName();
  305.     $page pnModGetVar($modname'page');
  306.     $totalpages pnModGetVar($modname'totalpages');
  307.     $perpage pnModGetVar($modname'perpage');
  308.     $startat pnModGetVar($modname'startat');
  309.     $output pnModGetVar($modname'output');
  310.     if ($page++==$totalpages{
  311.         $output .= _NM_FINISH."<br />";
  312.     else {
  313.         $startat += $perpage;
  314.  
  315.         $output .= _NM_PAGE1.($page-1)._NM_PAGE2.$totalpages.' '._NM_SEND._NM_OK._NM_NOWPROCCESS."<br />";
  316.         $output2 $output;
  317.         $output .= '
  318.     <form action="'.pnModUrl(pnModGetName(),'admin',dealwithform).'" method="post" name="mailform" id="mailform">
  319.     ';
  320.         $output .= mailusers_makehiddenfield("output",$output2);
  321.         $output .= mailusers_makehiddenfield("from",pnModGetVar($modname'from'));
  322.         $output .= mailusers_makehiddenfield("rpemail",pnModGetVar($modname'rpemail'));
  323.         $output .= mailusers_makehiddenfield("subject",pnModGetVar($modname'subject'));
  324.         $output .= mailusers_makehiddenfield("message",pnModGetVar($modname'message'));
  325.         $output .= mailusers_makehiddenfield("uname",pnModGetVar($modname'uname'));
  326.         $output .= mailusers_makehiddenfield("rname",pnModGetVar($modname'rname'));
  327.         $output .= mailusers_makehiddenfield("ugroup",pnModGetVar($modname'ugroup'));
  328.         $output .= mailusers_makehiddenfield("email",pnModGetVar($modname'email'));
  329.         $output .= mailusers_makehiddenfield("homepage",pnModGetVar($modname'homepage'));
  330.         $output .= mailusers_makehiddenfield("icq",pnModGetVar($modname'icq'));
  331.         $output .= mailusers_makehiddenfield("msn",pnModGetVar($modname'msn'));
  332.         $output .= mailusers_makehiddenfield("aim",pnModGetVar($modname'aim'));
  333.         $output .= mailusers_makehiddenfield("yim",pnModGetVar($modname'yim'));
  334.         $output .= mailusers_makehiddenfield("signature",pnModGetVar($modname'signature'));
  335.         $output .= mailusers_makehiddenfield("regdateafter",pnModGetVar($modname'regdateafter'));
  336.         $output .= mailusers_makehiddenfield("regdatebefore",pnModGetVar($modname'regdatebefore'));
  337.         $output .= mailusers_makehiddenfield("testonly",pnModGetVar($modname'testonly'));
  338.         $output .= mailusers_makehiddenfield("perpage",$perpage);
  339.         $output .= mailusers_makehiddenfield("startat",$startat);
  340.         $output .= mailusers_makehiddenfield("page",$page);
  341.         $output .= mailusers_makehiddenfield("totalpages",$totalpages);
  342.         $output .= '
  343.         <input type="submit" name="Submit" value="'._NM_SENDNEXTPAGE.'">
  344.     </form>
  345.     ';
  346.     }
  347.     return $output;
  348. }
  349.  
  350.  
  351. /**
  352.  * Create hidden field
  353.  *
  354.  * Utility function to create a hidden form field
  355.  *
  356.  * @author       Xiaoyu Huang
  357.  * @return       output       The main module admin page
  358.  */
  359. function mailusers_makehiddenfield($name,$value)
  360. {
  361.     return '<input name="'.$name.'" type="hidden" id="'.$name.'" value="'.$value.'">';
  362. }

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