OSDN Git Service

add ACS webapp, sql, htdocs
[acs/acs.git] / webapp / modules / User / actions / EditProfileAction.class.php
diff --git a/webapp/modules/User/actions/EditProfileAction.class.php b/webapp/modules/User/actions/EditProfileAction.class.php
new file mode 100644 (file)
index 0000000..c5d32d9
--- /dev/null
@@ -0,0 +1,157 @@
+<?php
+// $Id: EditProfileAction.class.php,v 2.0 2008/04/24 16:00:00 y-yuki Exp $
+
+class EditProfileAction extends BaseAction
+{
+       // GET
+       function getDefaultView() {
+               $context = $this->getContext();
+               $controller = $context->getController();
+               $request =  $context->getRequest();
+               $user = $context->getUser();
+
+               $acs_user_info_row = $user->getAttribute('acs_user_info_row');
+       
+               if (!$this->get_execute_privilege()) {
+                       $controller->forward(SECURE_MODULE, SECURE_ACTION);
+                       return;
+               }
+
+               $open_level_master_array = ACSDB::get_master_array('open_level');
+
+               if ($acs_user_info_row['is_acs_user'] && $acs_user_info_row['open_level_name'] == ACSMsg::get_mst('open_level_master','D03')) {
+                       // ¥Þ¥¤¥Ú¡¼¥¸Á´ÂΤ¬Èó¸ø³«¤Î¥æ¡¼¥¶ //
+
+                       // Èó¸ø³«¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£¤Î¾ðÊó¤ò¼èÆÀ
+                       $target_user_info_row = ACSUser::get_user_profile_row($acs_user_info_row['user_community_id'], 'include_private');
+
+               } elseif (!$acs_user_info_row['is_acs_user'] && $acs_user_info_row['is_ldap_user']) {
+                       // ¥·¥¹¥Æ¥à¤Ë̤ÅÐÏ¿¤ÎLDAP¥æ¡¼¥¶ //
+
+                       $ldap_user_info_row = ACSLDAP::get_ldap_user_info_row($acs_user_info_row['user_id']);
+
+                       $target_user_info_row['contents_row_array'] = array();
+
+                       // ¥Ë¥Ã¥¯¥Í¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤò»á̾¤È¤¹¤ë
+                       $target_user_info_row['community_name'] = $ldap_user_info_row['user_name'];
+
+                       $target_user_info_row['contents_row_array']['user_name'] = ACSCommunity::get_empty_contents_row(ACSMsg::get_mst('community_type_master','D10'), ACSMsg::get_mst('contents_type_master','D01'));
+                       $target_user_info_row['contents_row_array']['user_name']['contents_value'] = $ldap_user_info_row['user_name'];
+                       $target_user_info_row['contents_row_array']['mail_addr'] = ACSCommunity::get_empty_contents_row(ACSMsg::get_mst('community_type_master','D10'), ACSMsg::get_mst('contents_type_master','D02'));
+                       $target_user_info_row['contents_row_array']['mail_addr']['contents_value'] = $ldap_user_info_row['mail_addr'];
+                       $target_user_info_row['contents_row_array']['belonging'] = ACSCommunity::get_empty_contents_row(ACSMsg::get_mst('community_type_master','D10'), ACSMsg::get_mst('contents_type_master','D03'));
+                       $target_user_info_row['contents_row_array']['belonging']['contents_value'] = $ldap_user_info_row['belonging'];
+                       $target_user_info_row['contents_row_array']['friends_list'] = ACSCommunity::get_empty_contents_row(ACSMsg::get_mst('community_type_master','D10'), ACSMsg::get_mst('contents_type_master','D11'));
+                       $target_user_info_row['contents_row_array']['mail_lang'] = ACSCommunity::get_empty_contents_row(ACSMsg::get_mst('community_type_master','D10'), ACSMsg::get_mst('contents_type_master','D51'));
+
+                       // ¿·µ¬LDAP¥æ¡¼¥¶¤Ç¤¢¤ë
+                       $is_new_ldap_user = true;
+
+               } else {
+                       // ÂоݤȤʤë¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¤ò¼èÆÀ
+                       $user_community_id = $request->ACSgetParameter('id');
+                       // ¥×¥í¥Õ¥£¡¼¥ë
+                       $target_user_info_row = ACSUser::get_user_profile_row($user_community_id);
+               }
+
+               // set
+               $request->setAttribute('target_user_info_row', $target_user_info_row);
+               $request->setAttribute('is_new_ldap_user', $is_new_ldap_user);
+
+               return View::INPUT;
+       }
+
+       // POST
+       function execute() {
+               $context = $this->getContext();
+               $controller = $context->getController();
+               $request =  $context->getRequest();
+               $user = $context->getUser();
+               
+               $acs_user_info_row = $user->getAttribute('acs_user_info_row');
+
+               // ÂоݤȤʤë¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¤ò¼èÆÀ
+               $user_community_id = $request->ACSgetParameter('id');
+
+               $form = $request->ACSGetParameters();
+
+               if ($acs_user_info_row['is_acs_user']) {
+                       // »á̾¤ÏÊѹ¹¤·¤Ê¤¤
+                       $form['user_name'] = $acs_user_info_row['user_name'];
+
+               } else {
+                       $form['user_id'] = $acs_user_info_row['user_id'];
+                       // LDAP¤«¤é»á̾¼èÆÀ
+                       $ldap_user_info_row = ACSLDAP::get_ldap_user_info_row($acs_user_info_row['user_id']);
+                       $form['user_name'] = $ldap_user_info_row['user_name'];
+               }
+
+               // INSERT
+               $ret = ACSUser::set_user_profile($acs_user_info_row, $form);
+
+               // ¸À¸ì¤ÎÀÚÂØ
+               ACSMsg::set_lang($form['mail_lang']);
+               ACSMsg::set_lang_cookie($form['mail_lang']);
+
+               if ($ret) {
+                       // ½ñ¤­¹þ¤ß¸å¡¢GET¤Î½èÍý¤Ø
+                       header("Location: ./");
+               } else {
+                       exit;
+               }
+       }
+
+       function getRequestMethods() {
+               return Request::POST;
+       }
+
+       function isSecure () {
+               return false;
+       }
+
+       function getCredential() {
+               return array('USER_PAGE_OWNER');
+       }
+
+       function validate () {
+               return TRUE;
+       }
+
+       function registerValidators (&$validatorManager) {
+               /* É¬¿Ü¥Á¥§¥Ã¥¯ */
+               parent::regValidateName($validatorManager, 
+                               "mail_addr", 
+                               true, 
+                               ACSMsg::get_msg('User', 'EditProfileAction.class.php', 'M001'));
+               parent::regValidateName($validatorManager, 
+                               "community_name", 
+                               true, 
+                               ACSMsg::get_msg('User', 'EditProfileAction.class.php', 'M002'));
+       }
+
+       function handleError () {
+               $context = $this->getContext();
+               $controller = $context->getController();
+               $request =  $context->getRequest();
+               $user = $context->getUser();
+               // ÆþÎÏÃͤò set
+               $form = $request->ACSGetParameters();
+               $request->setAttribute('form', $form);
+
+               // ÆþÎϲèÌÌɽ¼¨
+               return $this->getDefaultView();
+       }
+
+       function get_execute_privilege () {
+               $context = $this->getContext();
+               $user = $context->getUser();
+
+               // Ëܿͤǡ¢LDAPǧ¾Ú°Ê³°¤Î¾ì¹ç¤ÏOK
+               if ($user->hasCredential('USER_PAGE_OWNER')) {
+                       return true;
+               }
+               return false;
+       }
+}
+
+?>