PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/contribution/trunk/extension/ezregion/ezpublish-src/ezuser/admin/useredit.php

https://gitlab.com/BGCX067/ezcommunity2-svn-to-git
PHP | 422 lines | 365 code | 32 blank | 25 comment | 23 complexity | 4306c4df7d2c7c5327c953300a51f33f MD5 | raw file
  1. <?php
  2. //
  3. // $Id: useredit.php,v 1.34 2001/10/05 09:42:43 bf Exp $
  4. //
  5. // Created on: <20-Sep-2000 13:32:11 ce>
  6. //
  7. // This source file is part of eZ publish, publishing software.
  8. //
  9. // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
  10. //
  11. // This program is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU General Public License
  13. // as published by the Free Software Foundation; either version 2
  14. // of the License, or (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program; if not, write to the Free Software
  23. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
  24. //
  25. include_once( "classes/INIFile.php" );
  26. include_once( "classes/eztemplate.php" );
  27. include_once( "classes/ezhttptool.php" );
  28. $ini =& INIFile::globalINI();
  29. $Language = $ini->read_var( "eZUserMain", "Language" );
  30. $error = new INIFIle( "ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
  31. include_once( "ezmail/classes/ezmail.php" );
  32. include_once( "classes/ezlog.php" );
  33. include_once( "ezuser/classes/ezuser.php" );
  34. include_once( "ezuser/classes/ezusergroup.php" );
  35. require( "ezuser/admin/admincheck.php" );
  36. if ( isSet ( $DeleteUsers ) )
  37. {
  38. $Action = "DeleteUsers";
  39. }
  40. if ( isSet( $Back ) )
  41. {
  42. eZHTTPTool::header( "Location: /user/userlist/" );
  43. exit();
  44. }
  45. // do not allow editing users with root access while you do not.
  46. $currentUser = eZUser::currentUser();
  47. if( isset( $UserID ) )
  48. {
  49. $editUser = new eZUser( $UserID );
  50. if( !$currentUser->hasRootAccess() && $editUser->hasRootAccess() )
  51. {
  52. $info = urlencode( "Can't edit a user with root priveliges." );
  53. eZHTTPTool::header( "Location: /error/403?Info=$info" );
  54. exit();
  55. }
  56. }
  57. if ( $Action == "insert" )
  58. {
  59. if ( eZPermission::checkPermission( $user, "eZUser", "UserAdd" ) )
  60. {
  61. if ( $Login != "" &&
  62. $Email != "" &&
  63. $FirstName != "" &&
  64. $LastName != "" &&
  65. $SimultaneousLogins != "")
  66. {
  67. if ( ( $Password == $VerifyPassword ) && ( strlen( $VerifyPassword ) > 2 ) )
  68. {
  69. $user = new eZUser();
  70. $user->setLogin( $Login );
  71. if ( !$user->exists( $user->login() ) )
  72. {
  73. $tmp[0] = $Email;
  74. if ( eZMail::validate( $tmp[0] ) )
  75. {
  76. $user->setPassword( $Password );
  77. $user->setEmail( $Email );
  78. $user->setFirstName( $FirstName );
  79. $user->setLastName( $LastName );
  80. $user->setSignature( $Signature );
  81. $user->setSimultaneousLogins( $SimultaneousLogins );
  82. if ( $InfoSubscription == "on" )
  83. $user->setInfoSubscription( true );
  84. else
  85. $user->setInfoSubscription( false );
  86. $user->store();
  87. eZLog::writeNotice( "User created: $FirstName $LastName ($Login) $Email $SimultaneousLogins from IP: $REMOTE_ADDR" );
  88. // Add user to groups
  89. $GroupArray = array_unique( array_merge( $GroupArray, $MainGroup ) );
  90. $group = new eZUserGroup();
  91. $user->get( $user->id() );
  92. $user->removeGroups();
  93. foreach ( $GroupArray as $GroupID )
  94. {
  95. $group = new eZUserGroup();
  96. // $user->get( $user->id() );
  97. // $user->removeGroups();
  98. $group->get( $GroupID );
  99. if ( ( $group->isRoot() && $currentUser->hasRootAccess() ) || !$group->isRoot() )
  100. {
  101. $group->adduser( $user );
  102. $groupname = $group->name();
  103. eZLog::writeNotice( "User added to group: $groupname from IP: $REMOTE_ADDR" );
  104. }
  105. }
  106. $user->setGroupDefinition( $MainGroup );
  107. eZHTTPTool::header( "Location: /user/userlist/" );
  108. exit();
  109. }
  110. else
  111. {
  112. $error_msg = $error->read_var( "strings", "error_email" );
  113. }
  114. }
  115. else
  116. {
  117. $error_msg = $error->read_var( "strings", "error_user_exists" );
  118. }
  119. }
  120. else
  121. {
  122. $error_msg = $error->read_var( "strings", "error_password" );
  123. }
  124. }
  125. else
  126. {
  127. $error_msg = $error->read_var( "strings", "error_missingdata" );
  128. }
  129. }
  130. else
  131. {
  132. $error_msg = $error->read_var( "strings", "error_norights" );
  133. }
  134. }
  135. if ( $Action == "update" )
  136. {
  137. if ( eZPermission::checkPermission( $user, "eZUser", "UserModify" ) )
  138. {
  139. if ( $Login != "" &&
  140. $Email != "" &&
  141. $FirstName != "" &&
  142. $LastName != "" &&
  143. $SimultaneousLogins != "")
  144. {
  145. if ( ( ( $Password == $VerifyPassword ) && ( strlen( $VerifyPassword ) > 2 ) ) ||
  146. ( ( $Password == $VerifyPassword ) && ( strlen( $VerifyPassword ) == 0 ) ) )
  147. {
  148. $user->setLogin( $Login );
  149. {
  150. if ( eZMail::validate( $Email ) )
  151. {
  152. $user = new eZUser();
  153. $user->get( $UserID );
  154. $user->setEmail( $Email );
  155. $user->setSignature( $Signature );
  156. if ( $InfoSubscription == "on" )
  157. $user->setInfoSubscription( true );
  158. else
  159. $user->setInfoSubscription( false );
  160. $user->setFirstName( $FirstName );
  161. $user->setLastName( $LastName );
  162. $user->setSimultaneousLogins( $SimultaneousLogins );
  163. if ( strlen( $Password ) > 0 )
  164. {
  165. $user->setPassword( $Password );
  166. }
  167. $user->store();
  168. eZLog::writeNotice( "User updated: $FirstName $LastName ($Login) $Email from IP: $REMOTE_ADDR" );
  169. // Remove user from groups
  170. $user->removeGroups();
  171. // Add user to groups
  172. $GroupArray = array_unique( array_merge( $GroupArray, $MainGroup ) );
  173. $group = new eZUserGroup();
  174. $user->get( $user->id() );
  175. $user->removeGroups();
  176. foreach ( $GroupArray as $GroupID )
  177. {
  178. $group = new eZUserGroup();
  179. // $user->get( $user->id() );
  180. // $user->removeGroups();
  181. $group->get( $GroupID );
  182. // if ( ( $group->isRoot() && $currentUser->hasRootAccess() ) || !$group->isRoot() )
  183. {
  184. $group->adduser( $user );
  185. $groupname = $group->name();
  186. eZLog::writeNotice( "User added to group: $groupname from IP: $REMOTE_ADDR" );
  187. }
  188. }
  189. $user->setGroupDefinition( $MainGroup );
  190. eZHTTPTool::header( "Location: /user/userlist/" );
  191. exit();
  192. }
  193. else
  194. {
  195. $error_msg = $error->read_var( "strings", "error_email" );
  196. }
  197. }
  198. }
  199. else
  200. {
  201. $error_msg = $error->read_var( "strings", "error_password" );
  202. }
  203. }
  204. else
  205. {
  206. $error_msg = $error->read_var( "strings", "error_missingdata" );
  207. }
  208. }
  209. else
  210. {
  211. $error_msg = $error->read_var( "strings", "error_norights" );
  212. }
  213. $ActionValue = "update";
  214. }
  215. if ( $Action == "delete" )
  216. {
  217. if ( eZPermission::checkPermission( $user, "eZUser", "UserDelete" ) )
  218. {
  219. $user = new eZUser();
  220. $user->get( $UserID );
  221. $firstName = $user->firstName();
  222. $lastName = $user->lastName();
  223. $email = $user->email();
  224. $login = $user->login();
  225. $simultaneousLogins = $user->simultaneousLogins();
  226. $user->delete();
  227. eZLog::writeNotice( "User deleted: $firstname $lastname ($login) $email $simultaneousLogins from IP: $REMOTE_ADDR" );
  228. eZHTTPTool::header( "Location: /user/userlist/" );
  229. exit();
  230. }
  231. else
  232. {
  233. $error_msg = $error->read_var( "strings", "error_norights" );
  234. }
  235. }
  236. $currentUser = eZUser::currentUser();
  237. if ( $Action == "DeleteUsers" )
  238. {
  239. if( eZPermission::checkPermission( $user, "eZUser", "UserDelete" ) )
  240. {
  241. if ( count ( $UserArrayID ) != 0 )
  242. {
  243. foreach( $UserArrayID as $UserID )
  244. {
  245. $user = new eZUser( $UserID );
  246. $login = $user->login();
  247. if( $user->hasRootAccess() && !$currentUser->hasRootAccess() )
  248. {
  249. $currentLogin = $currentUser->login();
  250. eZLog::writeNotice( "$currentLogin failed to delete user $login since he can't delete users with root privelidges." );
  251. }
  252. else
  253. {
  254. $firstName = $user->firstName();
  255. $lastName = $user->lastName();
  256. $email = $user->email();
  257. $login = $user->login();
  258. $simultaneousLogins = $user->simultaneousLogins();
  259. $user->delete();
  260. eZLog::writeNotice( "User deleted: $firstname $lastname ($login) $email $simultaneousLogins from IP: $REMOTE_ADDR" );
  261. }
  262. }
  263. }
  264. }
  265. eZHTTPTool::header( "Location: /user/userlist/" );
  266. exit();
  267. }
  268. $t = new eZTemplate( "ezuser/admin/" . $ini->read_var( "eZUserMain", "AdminTemplateDir" ),
  269. "ezuser/admin/" . "/intl", $Language, "useredit.php" );
  270. $t->setAllStrings();
  271. $t->set_file( array(
  272. "user_edit" => "useredit.tpl"
  273. ) );
  274. $t->set_block( "user_edit", "main_group_item_tpl", "main_group_item" );
  275. $t->set_block( "user_edit", "group_item_tpl", "group_item" );
  276. if ( $Action == "new" )
  277. {
  278. $FirstName = "";
  279. $Lastname = "";
  280. $Email = "";
  281. $Login = "";
  282. $SimultaneousLogins = $ini->read_var( "eZUserMain", "DefaultSimultaneousLogins" );
  283. }
  284. $ActionValue = "insert";
  285. if ( $Action == "update" )
  286. {
  287. $ActionValue = "update";
  288. }
  289. $headline = new INIFIle( "ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
  290. $t->set_var( "head_line", $headline->read_var( "strings", "head_line_insert" ) );
  291. $group = new eZUserGroup();
  292. $groupList = $group->getAll();
  293. $user = 0;
  294. $t->set_var( "read_only", "" );
  295. if ( $Action == "edit" )
  296. {
  297. $user = new eZUser();
  298. $user->get( $UserID );
  299. if( $user->infoSubscription() == true )
  300. $InfoSubscription = "checked";
  301. else
  302. $InfoSubscription = "";
  303. $FirstName = $user->firstName();
  304. $LastName = $user->lastName();
  305. $Email = $user->email();
  306. $Login = $user->login();
  307. $Signature = $user->signature();
  308. $SimultaneousLogins = $user->simultaneousLogins();
  309. $headline = new INIFile( "ezuser/admin/intl/" . $Language . "/useredit.php.ini", false );
  310. $t->set_var( "head_line", $headline->read_var( "strings", "head_line_edit" ) );
  311. $t->set_var( "read_only", "readonly=readonly" );
  312. $ActionValue = "update";
  313. }
  314. else // either new or failed edit... must put htmlspecialchars on stuff we got from form.
  315. {
  316. $FirstName = htmlspecialchars( $FirstName );
  317. $LastName = htmlspecialchars( $LastName );
  318. $Login = htmlspecialchars( $Login );
  319. $Signature = htmlspecialchars( $Signature );
  320. $Email = htmlspecialchars( $Email );
  321. $user =& eZUser::currentUser();
  322. }
  323. $mainGroup = $user->groupDefinition();
  324. $groupArray = $user->groups();
  325. foreach ( $groupList as $groupItem )
  326. {
  327. $t->set_var( "group_name", $groupItem->name() );
  328. $t->set_var( "group_id", $groupItem->id() );
  329. if ( $mainGroup == $groupItem->id() )
  330. $t->set_var( "main_selected", "selected" );
  331. else
  332. $t->set_var( "main_selected", "" );
  333. // add validation code here. $user->isValid();
  334. if ( $user )
  335. {
  336. $found = false;
  337. foreach ( $groupArray as $group )
  338. {
  339. if ( $group->id() == $groupItem->id() && $group->id() != $mainGroup )
  340. {
  341. $found = true;
  342. }
  343. }
  344. if ( $found == true )
  345. $t->set_var( "selected", "selected" );
  346. else
  347. $t->set_var( "selected", "" );
  348. }
  349. else
  350. {
  351. $t->set_var( "selected", "" );
  352. }
  353. $t->parse( "main_group_item", "main_group_item_tpl", true );
  354. $t->parse( "group_item", "group_item_tpl", true );
  355. }
  356. $t->set_var( "info_subscription", $InfoSubscription );
  357. $t->set_var( "error", $error_msg );
  358. $t->set_var( "first_name_value", $FirstName );
  359. $t->set_var( "last_name_value", $LastName );
  360. $t->set_var( "email_value", $Email );
  361. $t->set_var( "login_value", $Login );
  362. $t->set_var( "signature", $Signature );
  363. $t->set_var( "password_value", "" );
  364. $t->set_var( "verify_password_value", "" );
  365. $t->set_var( "action_value", $ActionValue );
  366. $t->set_var( "user_id", $UserID );
  367. $t->set_var( "simultaneouslogins_value", $SimultaneousLogins );
  368. $t->pparse( "output", "user_edit" );
  369. ?>