phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file subs_update.php

Documentation is available at subs_update.php

  1. <?php
  2. /**
  3.  * This file updates the current user's subscriptions!
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  *  {@internal Open Source relicensing agreement:
  21.  *  }}}
  22.  *
  23.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  24.  * @author fplanque: Francois PLANQUE
  25.  *
  26.  * @todo integrate it into the templates to avoid ugly die() on error and confusing redirect on success.
  27.  *
  28.  * @package pond
  29.  */
  30.  
  31. /**
  32.  * Initialize everything:
  33.  */
  34. require_once dirname(__FILE__).'/../qp_config/_config.php';
  35.  
  36. require_once $inc_path.'_main.inc.php';
  37.  
  38. // Getting GET or POST parameters:
  39. param'checkuser_id''integer'true );
  40. param'newuser_email''string'true );
  41. param'newuser_notify''integer');
  42. param'subs_blog_IDs''string'true );
  43.  
  44. /**
  45.  * Basic security checks:
  46.  */
  47. ifis_logged_in() )
  48. // must be logged in!
  49.     bad_request_dieT_('You are not logged in.') );
  50. }
  51.  
  52. if$checkuser_id != $current_User->ID )
  53. // Can only edit your own profile
  54.     bad_request_die'You are not logged in under the same account you are trying to modify.' );
  55. }
  56.  
  57. if$demo_mode && ($current_User->ID == 1
  58.     || $current_User->login == 'demouser'
  59.     || $current_User->login == 'demoblogger'
  60.     || $current_User->login == 'demospecial') )
  61. {
  62.     bad_request_die'Demo mode: you cannot edit the admin\'s or any demo-name\'s profile!<br />[<a href="javascript:history.go(-1)">'
  63.                 . T_('Back to profile''</a>]' );
  64. }
  65.  
  66. /**
  67.  * Additional checks:
  68.  */
  69. profile_check_paramsarray'email' => array($newuser_email'newuser_email') ) );
  70.  
  71.  
  72. if$Messages->count'error' ) )
  73. {
  74.     // TODO: (legacy) dh> display errors with the form itself
  75.     header_content_type'text/html' )// sets charset
  76.     $Messages->displayT_('Cannot update profile. Please correct the following errors:'),
  77.             '[<a href="javascript:history.go(-1)">' T_('Back to profile''</a>]' );
  78.     exit(0);
  79. }
  80.  
  81.  
  82. // Do the profile update:
  83. $current_User->set_email$newuser_email );
  84. $current_User->set'notify'$newuser_notify );
  85.  
  86. $current_User->dbupdate();
  87.  
  88.  
  89. // Work the blogs:
  90. $subscription_values array();
  91. $unsubscribed array();
  92. $subs_blog_IDs explode','$subs_blog_IDs );
  93. foreach$subs_blog_IDs as $loop_blog_ID )
  94. {
  95.     // Make sure no dirty hack is coming in here:
  96.     $loop_blog_ID intval$loop_blog_ID );
  97.  
  98.     // Get checkbox values:
  99.     $sub_items    param'sub_items_'.$loop_blog_ID,    'integer');
  100.     $sub_comments param'sub_comments_'.$loop_blog_ID'integer');
  101.  
  102.     if$sub_items || $sub_comments )
  103.     {    // We have a subscription for this blog
  104.         $subscription_values["$loop_blog_ID$current_User->ID$sub_items$sub_comments )";
  105.     }
  106.     else
  107.     {    // No subscription here:
  108.         $unsubscribed[$loop_blog_ID;
  109.     }
  110. }
  111.  
  112. // Note: we do not check if subscriptions are allowed here, but we check at the time we're about to send something
  113. ifcount($subscription_values) )
  114. {    // We need to record values:
  115.     $DB->query'REPLACE INTO T_subscriptions( sub_coll_ID, sub_user_ID, sub_items, sub_comments )
  116.                                 VALUES '.implode', '$subscription_values ) );
  117. }
  118.  
  119. ifcount($unsubscribed) )
  120. {    // We need to make sure some values are cleared:
  121.     $DB->query'DELETE FROM T_subscriptions
  122.                                  WHERE sub_user_ID = '.$current_User->ID.'
  123.                                       AND sub_coll_ID IN ('.implode', '$unsubscribed ).')' );
  124. }
  125.  
  126.  
  127. $Messages->addT_('Your profile & subscriptions have been updated.')'success' );
  128.  
  129.  
  130. // redirect Will save $Messages into Session:
  131.  
  132. ?>