OSDN Git Service

add ACS webapp, sql, htdocs
[acs/acs.git] / webapp / lib / class / ACSCommunity.class.php
diff --git a/webapp/lib/class/ACSCommunity.class.php b/webapp/lib/class/ACSCommunity.class.php
new file mode 100644 (file)
index 0000000..e06e248
--- /dev/null
@@ -0,0 +1,1526 @@
+<?php
+// $Id: ACSCommunity.class.php,v 1.44 2006/12/28 07:36:06 w-ota Exp $
+
+/*
+ * ¥³¥ß¥å¥Ë¥Æ¥£
+ */
+class ACSCommunity {
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó
+        */
+       static function get_community_row($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT *";
+               $sql .= " FROM ((community LEFT OUTER JOIN category_master ON community.category_code = category_master.category_code)";
+               $sql .= "  LEFT OUTER JOIN community_image_file USING(community_id)) as JOINED_COMMUNITY,"; 
+               $sql .= "  community_type_master";
+               $sql .= " WHERE JOINED_COMMUNITY.community_id = '$community_id'";
+               $sql .= "  AND JOINED_COMMUNITY.community_type_code = community_type_master.community_type_code";
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND JOINED_COMMUNITY.delete_flag != 't'";
+
+               $row = ACSDB::_get_row($sql);
+               return $row;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó(¥×¥í¥Õ¥£¡¼¥ë)¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó
+        */
+       static function get_community_profile_row($community_id) {
+               $community_row = ACSCommunity::get_community_row($community_id);
+               
+               // ¥×¥í¥Õ¥£¡¼¥ë (contents)
+               $community_row['contents_row_array'] = array();
+               $community_row['contents_row_array']['community_profile'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D07'));
+               $community_row['contents_row_array']['bbs'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D41'));
+               $community_row['contents_row_array']['community_folder'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D31'));
+               $community_row['contents_row_array']['self'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D00'));
+               $community_row['contents_row_array']['ml_addr'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D61'));
+               $community_row['contents_row_array']['ml_status'] = 
+                               ACSCommunity::get_contents_row($community_id, ACSMsg::get_mst('contents_type_master','D62'));
+
+               // ¥Ç¡¼¥¿Ìµ¤·¤Î¾ì¹ç¤Ï¶õ¤Îarray¤òÆþ¤ì¤ë
+               foreach ($community_row['contents_row_array'] as $contents_key => $contents_row) {
+                       if (!$contents_row) {
+                               $community_row['contents_row_array'][$contents_key] = array();
+                       }
+               }
+
+
+               // »²²Ã»ñ³Ê
+               $community_row['join_trusted_community_row_array'] = ACSCommunity::get_join_trusted_community_row_array($community_id);
+
+               // ¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£
+               // bbs (·Ç¼¨ÈÄ)
+               $community_row['contents_row_array']['bbs']['trusted_community_row_array'] = ACSCommunity::get_contents_trusted_community_row_array($community_id, $community_row['contents_row_array']['bbs']['contents_type_code'], $community_row['contents_row_array']['bbs']['open_level_code']);
+               // community_folder (¥³¥ß¥å¥Ë¥Æ¥£¥Õ¥©¥ë¥À)
+               $community_row['contents_row_array']['community_folder']['trusted_community_row_array'] = ACSCommunity::get_contents_trusted_community_row_array($community_id, $community_row['contents_row_array']['community_folder']['contents_type_code'], $community_row['contents_row_array']['community_folder']['open_level_code']);
+
+               return $community_row;
+       }
+
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó
+        * return À®¸ù(¥³¥ß¥å¥Ë¥Æ¥£ID) / ¼ºÇÔ(false)
+        */
+       static function set_community($form) {
+               // ¥³¥ß¥å¥Ë¥Æ¥£¼ïÊÌ¥Þ¥¹¥¿
+               $community_type_master_array = ACSDB::get_master_array('community_type');
+               //$community_type_code = array_search('¥³¥ß¥å¥Ë¥Æ¥£', $community_type_master_array);
+               $community_type_code = array_search(ACSMsg::get_mst('community_type_master','D40'), $community_type_master_array);
+
+               // ¥³¥ó¥Æ¥ó¥Ä¼ïÊÌ¥Þ¥¹¥¿
+               $contents_type_master_array = ACSDB::get_master_array('contents_type');
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¼ïÊÌ¥Þ¥¹¥¿
+               $community_member_type_master_array = ACSDB::get_master_array('community_member_type');
+
+               $org_form = $form;
+
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               // BEGIN
+               ACSDB::_do_query("BEGIN");
+
+               // (1) ¥³¥ß¥å¥Ë¥Æ¥£ (community)
+               $community_id_seq = ACSDB::get_next_seq('community_id_seq');
+               $admission_flag = ACSLib::get_pg_boolean($org_form['admission_flag']);
+               $sql  = "INSERT INTO community";
+               $sql .= " (community_id, community_name, community_type_code, category_code, admission_flag)";
+               $sql .= " VALUES ('$community_id_seq', $form[community_name], '$community_type_code', $form[category_code], '$admission_flag')";
+               $ret = ACSDB::_do_query($sql);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // contents
+               // (2-1) (¥³¥ß¥å¥Ë¥Æ¥£Á´ÂÎ)
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               //$contents_form['contents_type_code'] = array_search('Á´ÂÎ', $contents_type_master_array);
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D00'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = ACSAccessControl::get_default_open_level_code(ACSMsg::get_mst('community_type_master','D40'), ACSMsg::get_mst('contents_type_master','D00'));
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (2-2) ¥³¥ß¥å¥Ë¥Æ¥£¥×¥í¥Õ¥£¡¼¥ë
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D07'), $contents_type_master_array);
+               $contents_form['contents_value'] = $org_form['community_profile'];
+               $contents_form['open_level_code'] = ACSAccessControl::get_default_open_level_code(ACSMsg::get_mst('community_type_master','D40'), ACSMsg::get_mst('contents_type_master','D07'));
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (3) »²²Ã»ñ³Ê (join_trusted_community)
+               if (is_array($org_form['join_trusted_community_id_array'])) {
+                       $join_trusted_community_form = array();
+                       $join_trusted_community_form['community_id'] = $community_id_seq;
+                       foreach ($org_form['join_trusted_community_id_array'] as $trusted_community_id) {
+                               $join_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_join_trusted_community($join_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (4) ¸ø³«ÈÏ°Ï ÅŻҷǼ¨ÈÄ
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D41'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['bbs_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               // contents_trusted_community
+               if (is_array($org_form['bbs_trusted_community_id_array'])) {
+                       $contents_trusted_community_form = array();
+                       $contents_trusted_community_form['community_id'] = $community_id_seq;
+                       $contents_trusted_community_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D41'), $contents_type_master_array);
+                       $contents_trusted_community_form['open_level_code'] = $org_form['bbs_open_level_code'];
+                       foreach ($org_form['bbs_trusted_community_id_array'] as $trusted_community_id) {
+                               $contents_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_contents_trusted_community($contents_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (5) ¸ø³«ÈÏ°Ï ¥³¥ß¥å¥Ë¥Æ¥£¥Õ¥©¥ë¥À (cotents)
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D31'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['community_folder_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               // contents_trusted_community
+               if (is_array($org_form['community_folder_trusted_community_id_array'])) {
+                       $contents_trusted_community_form = array();
+                       $contents_trusted_community_form['community_id'] = $community_id_seq;
+                       $contents_trusted_community_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D31'), $contents_type_master_array);
+                       $contents_trusted_community_form['open_level_code'] = $org_form['community_folder_open_level_code'];
+                       foreach ($org_form['community_folder_trusted_community_id_array'] as $trusted_community_id) {
+                               $contents_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_contents_trusted_community($contents_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (6) ¸ø³«ÈÏ°Ï Á´ÂÎ
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               //$contents_form['contents_type_code'] = array_search('Á´ÂÎ', $contents_type_master_array);
+               $contents_form['contents_type_code'] = 
+                               array_search(ACSMsg::get_mst('contents_type_master','D00'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['self_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (7) ¥³¥ß¥å¥Ë¥Æ¥£´ÉÍý¼Ô¤ò¥»¥Ã¥È¤¹¤ë
+               $community_admin_form = array();
+               $community_admin_form['community_id'] = $community_id_seq;
+               $community_admin_form['user_community_id'] = $org_form['user_community_id'];
+               $ret = ACSCommunity::set_community_admin($community_admin_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (8) ¥³¥ß¥å¥Ë¥Æ¥£ML
+               // contents
+               // ¥³¥ß¥å¥Ë¥Æ¥£ML¥¢¥É¥ì¥¹
+               if ($org_form['community_ml_address']) {
+                       $contents_form = array();
+                       $contents_form['community_id'] = $community_id_seq;
+                       $contents_form['contents_type_code'] = 
+                                       array_search(ACSMsg::get_mst('contents_type_master','D61'), 
+                                       $contents_type_master_array);
+                       $contents_form['contents_value'] = $org_form['community_ml_address'];
+                       $contents_form['open_level_code'] = 
+                                       ACSAccessControl::get_default_open_level_code(
+                                               ACSMsg::get_mst('community_type_master','D40'), 
+                                               ACSMsg::get_mst('contents_type_master','D61'));
+                       $ret = ACSCommunity::set_contents($contents_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+                       // ¥³¥ß¥å¥Ë¥Æ¥£ML¥¹¥Æ¡¼¥¿¥¹
+                       $contents_form = array();
+                       $contents_form['community_id'] = $community_id_seq;
+                       $contents_form['contents_type_code'] = 
+                                       array_search(ACSMsg::get_mst('contents_type_master','D62'), 
+                                       $contents_type_master_array);
+                       $contents_form['contents_value'] = 'QUEUE';
+                       $contents_form['open_level_code'] = 
+                                       ACSAccessControl::get_default_open_level_code(
+                                               ACSMsg::get_mst('community_type_master','D40'), 
+                                               ACSMsg::get_mst('contents_type_master','D62'));
+                       $ret = ACSCommunity::set_contents($contents_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+               }
+
+               // COMMIT
+               ACSDB::_do_query("COMMIT");
+
+               return $community_id_seq;
+       }
+
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£Ì¾¤ò¹¹¿·¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $community_name ¥³¥ß¥å¥Ë¥Æ¥£Ì¾
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_community_name($community_id, $community_name) {
+               $community_id = pg_escape_string($community_id);
+               $community_name = pg_escape_string($community_name);
+
+               $sql  = "UPDATE community";
+               $sql .= " SET";
+               $sql .= " community_name = '$community_name'";
+               $sql .= " WHERE community_id = '$community_id'";
+
+               $ret = ACSDB::_do_query($sql);
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ó¥Æ¥ó¥Ä¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $contents_type_name ¥³¥ó¥Æ¥ó¥Ä¼ïÊÌ̾
+        * @return ¥³¥ó¥Æ¥ó¥Ä¾ðÊó (Ï¢ÁÛÇÛÎó)
+        */
+       static function get_contents_row($community_id, $contents_type_name) {
+               $community_id = pg_escape_string($community_id);
+               $contents_type_name = pg_escape_string($contents_type_name);
+
+               $sql  = "SELECT contents.*, contents_type_master.*, open_level_master.*, community_type_master.*";
+               $sql .= " FROM contents, community, community_type_master, contents_type_master, open_level_master";
+               $sql .= " WHERE contents.community_id = '$community_id'";
+               $sql .= "  AND contents.community_id = community.community_id";
+               $sql .= "  AND community.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND contents.contents_type_code = contents_type_master.contents_type_code";
+               $sql .= "  AND contents_type_master.contents_type_name = '$contents_type_name'";
+               $sql .= "  AND contents.open_level_code = open_level_master.open_level_code";
+
+               $row = ACSDB::_get_row($sql);
+               return $row;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ó¥Æ¥ó¥Ä¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_type_name ¥³¥ß¥å¥Ë¥Æ¥£¼ïÊÌ̾
+        * @param $contents_type_name ¥³¥ó¥Æ¥ó¥Ä¼ïÊÌ̾
+        * @return ¥³¥ó¥Æ¥ó¥Ä¾ðÊó (Ï¢ÁÛÇÛÎó)
+        */
+       static function get_empty_contents_row($community_type_name, $contents_type_name) {
+               $community_type_name = pg_escape_string($community_type_name);
+               $contents_type_name = pg_escape_string($contents_type_name);
+
+               $sql  = "SELECT *";
+               $sql .= " FROM open_level_list, community_type_master, contents_type_master, open_level_master";
+               $sql .= " WHERE open_level_list.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND community_type_master.community_type_name = '$community_type_name'";
+               $sql .= "  AND open_level_list.contents_type_code = contents_type_master.contents_type_code";
+               $sql .= "  AND contents_type_master.contents_type_name = '$contents_type_name'";
+               $sql .= "  AND open_level_list.open_level_code = open_level_master.open_level_code";
+               $sql .= "  AND open_level_list.is_default = 't'";
+               $row = ACSDB::_get_row($sql);
+
+               return $row;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ó¥Æ¥ó¥Ä¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param ¥³¥ó¥Æ¥ó¥Ä¾ðÊó
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_contents($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               // DELETE
+               $sql  = "DELETE";
+               $sql .= " FROM contents";
+               $sql .= " WHERE community_id = $form[community_id]";
+               $sql .= "  AND contents_type_code = $form[contents_type_code]";
+               // open_level_code¤ò»ØÄꤷ¤Ê¤¤
+               $ret = ACSDB::_do_query($sql);
+
+               // INSERT
+               $sql  = "INSERT INTO contents";
+               $sql .= " (community_id, contents_type_code, contents_value, open_level_code)";
+               $sql .= " VALUES ($form[community_id], $form[contents_type_code], $form[contents_value], $form[open_level_code])";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /*
+        * ¥³¥ó¥Æ¥ó¥Ä¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $contents_type_code ¥³¥ó¥Æ¥ó¥Ä¼ïÊÌ¥³¡¼¥É
+        * @param $open_level_code ¸ø³«¥ì¥Ù¥ë¥³¡¼¥É
+        * @param $community_type_name ¥³¥ß¥å¥Ë¥Æ¥£¼ïÊÌ̾
+        * @return ¥³¥ó¥Æ¥ó¥Ä¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        */
+       static function get_contents_trusted_community_row_array($community_id, $contents_type_code, $open_level_code) {
+               $community_id = pg_escape_string($community_id);
+               $contents_type_code = pg_escape_string($contents_type_code);
+               $open_level_code = pg_escape_string($open_level_code);
+               $community_type_name = pg_escape_string($community_type_name);
+
+               $sql  = "SELECT community.community_id, community.community_name, community.community_type_code,community_type_master.community_type_name";
+               $sql .= " FROM contents_trusted_community, community, community_type_master";
+               $sql .= " WHERE contents_trusted_community.community_id = '$community_id'";
+               $sql .= "  AND contents_trusted_community.contents_type_code = '$contents_type_code'";
+               $sql .= "  AND contents_trusted_community.open_level_code = '$open_level_code'";
+               $sql .= "  AND contents_trusted_community.trusted_community_id = community.community_id";
+               $sql .= "  AND community.community_type_code = community_type_master.community_type_code";
+               $sql .= " ORDER BY community.community_name ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /*
+        * ¥³¥ó¥Æ¥ó¥Ä¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form ¥³¥ó¥Æ¥ó¥Ä¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_contents_trusted_community($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               $sql  = "INSERT INTO contents_trusted_community";
+               $sql .= " (community_id, contents_type_code, open_level_code, trusted_community_id)";
+               $sql .= " VALUES ($form[community_id], $form[contents_type_code], $form[open_level_code], $form[trusted_community_id])";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /*
+        * ¥³¥ó¥Æ¥ó¥Ä¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¹¹¿·¤¹¤ëÁ°½àÈ÷
+        *
+        * @param $community_id
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function update_contents_trusted_community($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+               
+               $sql  = "DELETE FROM contents_trusted_community";
+               $sql .= " WHERE community_id = $form[community_id]";
+               $sql .= "  AND contents_type_code = $form[contents_type_code]";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+       
+       /*
+        * »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id
+        * @return ¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_join_trusted_community_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT community.community_id, community.community_name";
+               $sql .= " FROM join_trusted_community, community";
+               $sql .= " WHERE join_trusted_community.community_id = '$community_id'";
+               $sql .= "  AND join_trusted_community.trusted_community_id = community.community_id";
+               $sql .= " ORDER BY community.community_name";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /*
+        * »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_join_trusted_community($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               $sql  = "INSERT INTO join_trusted_community";
+               $sql .= " (community_id, trusted_community_id)";
+               $sql .= " VALUES ($form[community_id], $form[trusted_community_id])";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /*
+        * »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤òºï½ü¤¹¤ë
+        *
+        * @param $form »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function delete_join_trusted_community($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               $sql  = "DELETE FROM join_trusted_community";
+               $sql .= " WHERE community_id = $form[community_id]";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+
+       /*
+        * »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¹¹¿·¤¹¤ë
+        *
+        * @param $form »²²Ã»ñ³Ê¤Î¿®ÍêºÑ¤ß¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function update_join_trusted_community($form) {
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               $sql  = "UPDATE join_trusted_community";
+               $sql .= " SET trusted_community_id = $form[trusted_community_id]";
+               $sql .= " WHERE community_id = $form[community_id]";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£´Ö¥ê¥ó¥¯¤òÀßÄꤹ¤ë
+        *
+        * @param $parent_community_id ¿Æ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $sub_community_id ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_community_link($parent_community_id, $sub_community_id) {
+               $parent_community_id = pg_escape_string($parent_community_id);
+               $sub_community_id = pg_escape_string($sub_community_id);
+
+               $sql  = "INSERT INTO sub_community";
+               $sql .= " (community_id, sub_community_id)";
+               $sql .= " VALUES ('$parent_community_id', '$sub_community_id')";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£´Ö¥ê¥ó¥¯¤òºï½ü¤¹¤ë
+        *
+        * @param $parent_community_id ¿Æ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $sub_community_id ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function delete_community_link($parent_community_id, $sub_community_id) {
+               $parent_community_id = pg_escape_string($parent_community_id);
+               $sub_community_id = pg_escape_string($sub_community_id);
+
+               $sql  = "DELETE FROM sub_community";
+               $sql .= " WHERE community_id = '$parent_community_id'";
+               $sql .= "  AND sub_community_id = '$sub_community_id'";
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+
+       /**
+        * ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_sub_community_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT SUB.community_id, SUB.community_name, SUB.file_id";
+               $sql .= " FROM community, sub_community, (community LEFT OUTER JOIN community_image_file USING(community_id)) as SUB";
+               $sql .= " WHERE community.community_id = '$community_id'";
+               $sql .= "  AND community.community_id = sub_community.community_id";
+               $sql .= "  AND sub_community.sub_community_id = SUB.community_id";
+               $sql .= " ORDER BY SUB.community_name ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $parent_community_id ¿Æ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $sub_community_id ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        */
+       static function get_sub_community_row($parent_community_id, $sub_community_id) {
+               $parent_community_id = pg_escape_string($parent_community_id);
+               $sub_community_id = pg_escape_string($sub_community_id);
+
+               $sql  = "SELECT SUB.*";
+               $sql .= " FROM community, community_type_master, sub_community, community as SUB";
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code"; 
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'"; 
+               $sql .= "  AND community.community_id = '$parent_community_id'";
+               $sql .= "  AND community.community_id = sub_community.community_id";
+               $sql .= "  AND sub_community.sub_community_id = SUB.community_id";
+               $sql .= "  AND SUB.community_id = '$sub_community_id'";
+
+               $row = ACSDB::_get_row($sql);
+               return $row;
+       }
+
+       /**
+        * ¿Æ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¿Æ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_parent_community_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT community.community_id, community.community_name, community.file_id";
+               $sql .= " FROM (community LEFT OUTER JOIN community_image_file USING(community_id)) as community, sub_community, community as SUB";
+               $sql .= " WHERE community.community_id = sub_community.community_id";
+               $sql .= "  AND sub_community.sub_community_id = SUB.community_id";
+               $sql .= "  AND SUB.community_id = '$community_id'";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¿Æ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $parent_community_id ¿Æ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $sub_community_id ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¤Î¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥µ¥Ö¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó (Ï¢ÁÛÇÛÎó)
+        */
+       static function get_parent_community_row($parent_community_id, $sub_community_id) {
+               $parent_community_id = pg_escape_string($parent_community_id);
+               $sub_community_id = pg_escape_string($sub_community_id);
+
+               $sql  = "SELECT community.*";
+               $sql .= " FROM community, community_type_master, sub_community, community as SUB";
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code"; 
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'"; 
+               $sql .= "  AND community.community_id = '$parent_community_id'";
+               $sql .= "  AND community.community_id = sub_community.community_id";
+               $sql .= "  AND sub_community.sub_community_id = SUB.community_id";
+               $sql .= "  AND SUB.community_id = '$sub_community_id'";
+
+               $row = ACSDB::_get_row($sql);
+               return $row;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_community_member_user_info_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT user_info.user_community_id, USER_NAME_C.contents_value as user_name, USER_COMMUNITY.community_name, USER_COMMUNITY.file_id";
+               $sql .= " FROM community_member, user_info, (community LEFT OUTER JOIN community_image_file USING(community_id)) as USER_COMMUNITY, contents as USER_NAME_C, contents_type_master as USER_NAME_CTM";
+               $sql .= " WHERE community_member.community_id = '$community_id'";
+               $sql .= "  AND community_member.user_community_id = user_info.user_community_id";
+               $sql .= "  AND user_info.user_community_id = USER_COMMUNITY.community_id";
+               // »á̾
+               $sql .= "  AND user_info.user_community_id = USER_NAME_C.community_id";
+               $sql .= "  AND USER_NAME_C.contents_type_code = USER_NAME_CTM.contents_type_code";
+               $sql .= "  AND USER_NAME_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D01')."'";
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND USER_COMMUNITY.delete_flag != 't'";
+               $sql .= " ORDER BY user_info.user_id ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return array ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó¤Î°ìÍ÷
+        */
+       static function get_community_member_mail_address_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT user_info.user_id, user_info.user_community_id, " .
+                               " USER_MAIL_C.contents_value as mail_address, " .
+                               " USER_NAME_C.contents_value as user_community_name, " .
+                               " USER_LANG_C.contents_value as mail_lang " .
+                               " FROM ((((community_member " .
+                               "  INNER JOIN user_info " .
+                               "   ON community_member.user_community_id = user_info.user_community_id) " .
+                               "  INNER JOIN community as USER_COMMUNITY " .
+                               "   ON community_member.user_community_id = USER_COMMUNITY.community_id) " .
+                               "  INNER JOIN contents as USER_MAIL_C " .
+                               "   ON community_member.user_community_id = USER_MAIL_C.community_id) " .
+                               "  INNER JOIN contents as USER_NAME_C ".
+                               "   ON community_member.user_community_id = USER_NAME_C.community_id) " .
+                               "  LEFT JOIN (SELECT * FROM contents WHERE contents_type_code = '51') " .
+                               "     as USER_LANG_C ".
+                               "   ON community_member.user_community_id = USER_LANG_C.community_id " .
+                               " WHERE community_member.community_id = ${community_id}" .
+                               "  AND USER_MAIL_C.contents_type_code = '02' " . // 02...¥á¡¼¥ë¥¢¥É¥ì¥¹
+                               "  AND USER_NAME_C.contents_type_code = '01' " . // 01...»á̾
+
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND USER_COMMUNITY.delete_flag != 't'";
+               $sql .= " ORDER BY user_info.user_id ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¿Í¿ô¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return int ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¿Í¿ô
+        */
+       static function get_community_member_count($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT COUNT(*) AS cnt " .
+                               " FROM community_member " .
+                               "  INNER JOIN community as USER_COMMUNITY " .
+                               "   ON community_member.user_community_id = USER_COMMUNITY.community_id " .
+                               " WHERE community_member.community_id = ${community_id}" .
+                               "  AND USER_COMMUNITY.delete_flag != 't'";
+
+               return ACSDB::_get_value($sql);
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó¤Î·ï¿ô¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_community_member_num($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT count(*)";
+               $sql .= " FROM community_member, community as USER_COMMUNITY, user_info";
+               $sql .= " WHERE community_member.community_id = '$community_id'";
+               $sql .= "  AND community_member.user_community_id = user_info.user_community_id";
+               $sql .= "  AND user_info.user_community_id = USER_COMMUNITY.community_id";
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND USER_COMMUNITY.delete_flag != 't'";
+
+               $value = ACSDB::_get_value($sql);
+               return $value;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£´ÉÍý¼Ô¾ðÊó¤Î°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£´ÉÍý¼Ô¾ðÊó¤Î°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_community_admin_user_info_row_array($community_id) {
+               $community_id = pg_escape_string($community_id);
+
+               $sql  = "SELECT user_info.user_community_id, USER_NAME_C.contents_value as user_name, USER_COMMUNITY.community_name, USER_COMMUNITY.file_id";
+               $sql .= " FROM community_member, community_member_type_master, user_info, (community LEFT OUTER JOIN community_image_file USING(community_id)) as USER_COMMUNITY, contents as USER_NAME_C, contents_type_master as USER_NAME_CTM";
+               $sql .= " WHERE community_member.community_id = '$community_id'";
+               $sql .= "  AND community_member.community_member_type_code = community_member_type_master.community_member_type_code";
+               $sql .= "  AND community_member_type_master.community_member_type_name = '".ACSMsg::get_mst('community_member_type_master','D10')."'";
+               $sql .= "  AND community_member.user_community_id = user_info.user_community_id";
+               $sql .= "  AND user_info.user_community_id = USER_COMMUNITY.community_id";
+               // »á̾
+               $sql .= "  AND user_info.user_community_id = USER_NAME_C.community_id";
+               $sql .= "  AND USER_NAME_C.contents_type_code = USER_NAME_CTM.contents_type_code";
+               $sql .= "  AND USER_NAME_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D01')."'";
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND USER_COMMUNITY.delete_flag != 't'";
+               $sql .= " ORDER BY user_info.user_community_id ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¤òºï½ü¤¹¤ë
+        *
+        * @param  $community_id
+        * @param  $user_community_id_array
+        * @return true / false
+        */
+       static function delete_community_member ($community_id, $user_community_id_array) {
+               $target_user_community_id_str = implode(", ", $user_community_id_array);
+
+               $sql  = "DELETE";
+               $sql .= " FROM community_member";
+               $sql .= " WHERE community_id = '$community_id'";
+               $sql .=   " AND user_community_id IN ($target_user_community_id_str)";
+
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤òºï½ü¤¹¤ë
+        *   delete_flag ¤Ë true ¤ò¥»¥Ã¥È
+        *
+        * @param  $community_id
+        * @return true / false
+        */
+       static function delete_community ($community_id) {
+               $sql  = "UPDATE community";
+               $sql .= " SET";
+               $sql .= " delete_flag = 't'";
+               $sql .= " WHERE community_id = '$community_id'";
+
+               $ret = ACSDB::_do_query($sql);
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $user_community_id ¥¢¥¯¥»¥¹¼Ô¤Î¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID (Èó¸ø³«¥³¥ß¥å¥Ë¥Æ¥£¤â¸¡º÷·ë²Ì¤Ë´Þ¤á¤ë¤¿¤á)
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó
+        */
+       static function get_community_row_array($user_community_id = '') {
+               $sql  = "SELECT *";
+               $sql .= " FROM community, community_type_master,";
+               $sql .= "  contents as SELF_C, contents_type_master as SELF_CTM,";  // Á´ÂÎ
+               $sql .= "  open_level_master as SELF_OLM";                          // Á´ÂΤÎopen_level_master
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'";
+
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= " AND community.delete_flag != 't'";
+
+               $sql .= " AND community.community_id = SELF_C.community_id";
+               $sql .= " AND SELF_C.contents_type_code = SELF_CTM.contents_type_code";
+               $sql .= " AND SELF_C.open_level_code = SELF_OLM.open_level_code";
+               $sql .= " AND SELF_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D00')."'";
+               $sql .= " AND (";
+               $sql .= "       (";
+               // Èó¸ø³«¥³¥ß¥å¥Ë¥Æ¥£¤Ç¤Ê¤¤
+               $sql .= "         SELF_OLM.open_level_name != '".ACSMsg::get_mst('open_level_master','D03')."'";
+               $sql .= "       )";
+               if ($user_community_id) {
+                       $sql .= "   OR (";
+                       $sql .= "     SELF_OLM.open_level_name = '".ACSMsg::get_mst('open_level_master','D03')."'";
+                       $sql .= "     AND acs_is_community_member('$user_community_id', community.community_id)";
+                       $sql .= "   )";
+               }
+               $sql .= " )";
+
+               $sql .= " ORDER BY community.community_name ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤ò¸¡º÷¤¹¤ë
+        *
+        * @param $user_community_id ¥¢¥¯¥»¥¹¼Ô¤Î¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID (Èó¸ø³«¥³¥ß¥å¥Ë¥Æ¥£¤â¸¡º÷·ë²Ì¤Ë´Þ¤á¤ë¤¿¤á)
+        * @param $form ¸¡º÷¾ò·ï
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó
+        */
+       static function search_community_row_array($user_community_id = '', $form = array()) {
+               $sql  = "SELECT *";
+               if ($form['order'] == 'community_member_num') {
+                       $sql .= ", acs_get_community_member_num(community.community_id) as community_member_num";
+               }
+               $sql .= " FROM community, community_type_master,";
+               $sql .= "  category_master,";                                       // ¥«¥Æ¥´¥ê
+               $sql .= "  contents as SELF_C, contents_type_master as SELF_CTM,";  // Á´ÂÎ
+               $sql .= "  open_level_master as SELF_OLM,";                         // Á´ÂΤÎopen_level_master
+               $sql .= "  contents as COMMUNITY_PROFILE_C, contents_type_master as COMMUNITY_PROFILE_CTM";  // ¥³¥ß¥å¥Ë¥Æ¥£¥×¥í¥Õ¥£¡¼¥ë(³µÍ×)
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'";
+
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= " AND community.delete_flag != 't'";
+
+               $sql .= " AND community.community_id = SELF_C.community_id";
+               $sql .= " AND SELF_C.contents_type_code = SELF_CTM.contents_type_code";
+               $sql .= " AND SELF_C.open_level_code = SELF_OLM.open_level_code";
+               $sql .= " AND SELF_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D00')."'";
+               $sql .= " AND (";
+               $sql .= "       (";
+               // Èó¸ø³«¥³¥ß¥å¥Ë¥Æ¥£¤Ç¤Ê¤¤
+               $sql .= "         SELF_OLM.open_level_name != '".ACSMsg::get_mst('open_level_master','D03')."'";
+               $sql .= "       )";
+               if ($user_community_id) {
+                       $sql .= "   OR (";
+                       $sql .= "     SELF_OLM.open_level_name = '".ACSMsg::get_mst('open_level_master','D03')."'";
+                       $sql .= "     AND acs_is_community_member('$user_community_id', community.community_id)";
+                       $sql .= "   )";
+               }
+               $sql .= " )";
+
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥×¥í¥Õ¥£¡¼¥ë
+               $sql .= " AND community.community_id = COMMUNITY_PROFILE_C.community_id";
+               $sql .= " AND COMMUNITY_PROFILE_C.contents_type_code = COMMUNITY_PROFILE_CTM.contents_type_code";
+               $sql .= " AND COMMUNITY_PROFILE_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D07')."'";
+
+               // ¸¡º÷¾ò·ï //
+               // ¥­¡¼¥ï¡¼¥É
+               if ($form['q'] != '') {
+                       $query_array_array = ACSLib::get_query_array_array($form['q']);
+                       $where_sql = '';
+                       foreach ($query_array_array as $query_array) {
+                               if (!count($query_array)) {
+                                       continue;
+                               }
+
+                               $sub_where_sql = '';
+                               foreach ($query_array as $query) {
+                                       $query = pg_escape_string($query);
+                                       ACSLib::escape_ilike($query);
+
+                                       if ($sub_where_sql != '') {
+                                               $sub_where_sql .= " OR ";
+                                       }
+
+                                       $sub_where_sql .= "(";
+                                       $sub_where_sql .= " community.community_name ILIKE '%$query%'";
+                                       $sub_where_sql .= "  OR COMMUNITY_PROFILE_C.contents_value ILIKE '%$query%'";
+                                       $sub_where_sql .= "  OR category_master.category_name ILIKE '%$query%'";
+                                       $sub_where_sql .= ")";
+                               }
+
+                               if ($sub_where_sql != '') {
+                                       if ($where_sql != '') {
+                                               $where_sql .= " AND ";
+                                       }
+                                       $where_sql .= "($sub_where_sql)";
+                               }
+                       }
+
+                       if ($where_sql != '') {
+                               $sql .= " AND ($where_sql)";
+                       }
+               }
+
+               // ¥«¥Æ¥´¥ê
+               $sql .= " AND community.category_code = category_master.category_code";
+               if ($form['category_code']) {
+                       $sql .= " AND community.category_code = '" . pg_escape_string($form['category_code']) . "'";
+               }
+
+               // »²²Ã»ñ³Ê
+               if ($form['admission_flag'] == 't' || $form['admission_flag'] == 'f') {
+                       $sql .= " AND community.admission_flag = '$form[admission_flag]'";
+               }
+
+               // ORDER
+               if ($form['order'] == 'new') {
+                       $sql .= " ORDER BY community.register_date DESC";
+               } elseif ($form['order'] == 'community_member_num') {
+                       $sql .= " ORDER BY community_member_num DESC, community.community_name ASC";
+               } else {
+                       $sql .= " ORDER BY community.community_name ASC";
+               }
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¿·Ã女¥ß¥å¥Ë¥Æ¥£¾ðÊó°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @return ¿·Ã女¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_new_community_row_array() {
+               $limit = ACSSystemConfig::get_keyword_value(ACSMsg::get_mst('system_config_group','D02'), 'NEW_INFO_TOP_DISPLAY_MAX_COUNT');
+
+               $sql  = "SELECT *";
+               $sql .= " FROM community, community_type_master,";
+               $sql .= "  contents as SELF_C, contents_type_master as SELF_CTM,";  // Á´ÂÎ
+               $sql .= "  open_level_master as SELF_OLM";                          // Á´ÂΤÎopen_level_master
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'";
+
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= " AND community.delete_flag != 't'";
+               // Èó¸ø³«¥³¥ß¥å¥Ë¥Æ¥£¤Ç¤Ê¤¤
+               $sql .= " AND community.community_id = SELF_C.community_id";
+               $sql .= " AND SELF_C.contents_type_code = SELF_CTM.contents_type_code";
+               $sql .= " AND SELF_C.open_level_code = SELF_OLM.open_level_code";
+               $sql .= " AND SELF_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D00')."'";
+               $sql .= " AND SELF_OLM.open_level_name != '".ACSMsg::get_mst('open_level_master','D03')."'";
+
+               $sql .= " ORDER BY community.register_date DESC";
+               // LIMIT
+               $sql .= " LIMIT $limit";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¥é¥ó¥­¥ó¥°¾ðÊó¤ò¼èÆÀ¤¹¤ë
+        *
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¥é¥ó¥­¥ó¥°¾ðÊó¤Î°ìÍ÷
+        */
+       static function get_ranking_community_row_array() {
+               $limit = ACSSystemConfig::get_keyword_value(ACSMsg::get_mst('system_config_group','D02'), 'NEW_INFO_TOP_DISPLAY_MAX_COUNT');
+               $term = ACSSystemConfig::get_keyword_value(ACSMsg::get_mst('system_config_group','D05'), 'COMMUNITY_RANKING_COUNT_TERM');
+
+               $sql  = "SELECT community.community_id, community.community_name, community.file_id,";
+               $sql .= " (";
+               $sql .= "  acs_get_bbs_score_by_c_id(community.community_id, '$term')";
+               $sql .= "  + acs_get_bbs_res_score_by_c_id(community.community_id, '$term')";
+               $sql .= "  + acs_get_file_info_score(community.community_id, '$term')";
+               $sql .= " ) as ranking_score";
+
+               $sql .= " FROM (community LEFT OUTER JOIN community_image_file USING(community_id)) as community, community_type_master,";
+               $sql .= "  contents as SELF_C, contents_type_master as SELF_CTM, open_level_master as SELF_OLM"; // ¥³¥ß¥å¥Ë¥Æ¥£Á´ÂÎ
+
+               $sql .= " WHERE community.community_type_code = community_type_master.community_type_code";
+               $sql .= "  AND community_type_master.community_type_name = '".ACSMsg::get_mst('community_type_master','D40')."'";
+
+               // ºï½ü¥Õ¥é¥°OFF
+               $sql .= "  AND community.delete_flag != 't'";
+               // Á´ÂÎ=Èó¸ø³«¤ò½ü¤¯
+               $sql .= "  AND community.community_id = SELF_C.community_id";
+               $sql .= "  AND SELF_C.contents_type_code = SELF_CTM.contents_type_code";
+               $sql .= "  AND SELF_C.open_level_code = SELF_OLM.open_level_code";
+               $sql .= "  AND SELF_CTM.contents_type_name = '".ACSMsg::get_mst('contents_type_master','D00')."'";
+               $sql .= "  AND SELF_OLM.open_level_name != '".ACSMsg::get_mst('open_level_master','D03')."'";
+
+               $sql .= " ORDER BY ranking_score DESC";
+               // LIMIT
+               $sql .= " LIMIT $limit";
+
+               $row_array = ACSDB::_get_row_array($sql);
+
+               // 0pt¤Ï½ü³°
+               $new_row_array = array();
+               foreach ($row_array as $row) {
+                       if ($row['ranking_score'] > 0) {
+                               array_push($new_row_array, $row);
+                       }
+               }
+
+               return $new_row_array;
+       }
+
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î´ÉÍý¼Ô¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function update_community_admin($acs_user_info_row, $form) {
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¼ïÊÌ¥Þ¥¹¥¿
+               $community_member_type_master_array = ACSDB::get_master_array('community_member_type');
+               $community_admin_type_code = array_search(ACSMsg::get_mst('community_member_type_master','D10'), $community_member_type_master_array);
+               $community_member_type_code = array_search(ACSMsg::get_mst('community_member_type_master','D20'), $community_member_type_master_array);
+
+               $community_id = pg_escape_string($form['community_id']);
+
+               // BEGIN
+               ACSDB::_do_query("BEGIN");
+
+               // ¥¢¥¯¥»¥¹¼Ô°Ê³°¤ò¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¤È¤·¤ÆÀßÄê
+               $sql  = "UPDATE community_member";
+               $sql .= " SET community_member_type_code = '$community_member_type_code'";
+               $sql .= " WHERE user_community_id != '$acs_user_info_row[user_community_id]'";
+               $sql .= "  AND community_id = '$community_id'";
+               $ret = ACSDB::_do_query($sql);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               if (is_array($form['user_community_id_array'])) {
+                       // »ØÄꤵ¤ì¤¿¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID¤ò¥³¥ß¥å¥Ë¥Æ¥£´ÉÍý¼Ô¤È¤·¤ÆÀßÄê
+                       foreach ($form['user_community_id_array'] as $user_community_id) {
+                               $sql  = "UPDATE community_member";
+                               $sql .= " SET community_member_type_code = '$community_admin_type_code'";
+                               $sql .= " WHERE user_community_id = '$user_community_id'";
+                               $sql .= "  AND community_id = '$community_id'";
+                               $ret = ACSDB::_do_query($sql);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // COMMIT
+               ACSDB::_do_query("COMMIT");
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥á¥ó¥Ð(Èó´ÉÍý¼Ô)¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_community_admin($form) {
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¼ïÊÌ¥Þ¥¹¥¿
+               $community_member_type_master_array = ACSDB::get_master_array('community_member_type');
+
+               // $form['community_id']      »²²ÃÂоݤΥ³¥ß¥å¥Ë¥Æ¥£
+               // $form['user_community_id'] »²²Ã¤¹¤ë¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+               $form['community_member_type_code'] = array_search(ACSMsg::get_mst('community_member_type_master','D10'), $community_member_type_master_array);
+               $ret = ACSCommunityMemberModel::insert_community_member($form);
+
+               return $ret;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥á¥ó¥Ð(Èó´ÉÍý¼Ô)¤òÅÐÏ¿¤¹¤ë
+        *
+        * @param $form ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¾ðÊó
+        * @return À®¸ù(true) / ¼ºÇÔ(false)
+        */
+       static function set_community_member($form) {
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¼ïÊÌ¥Þ¥¹¥¿
+               $community_member_type_master_array = ACSDB::get_master_array('community_member_type');
+
+               // $form['community_id']      »²²ÃÂоݤΥ³¥ß¥å¥Ë¥Æ¥£
+               // $form['user_community_id'] »²²Ã¤¹¤ë¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+               $form['community_member_type_code'] = array_search(ACSMsg::get_mst('community_member_type_master','D20'), $community_member_type_master_array);
+               $ret = ACSCommunityMemberModel::insert_community_member($form);
+
+               return $ret;
+       }
+
+
+       // ÈÆÍÑ·Ï //
+
+       /**
+        * ¥æ¡¼¥¶¤¬¥³¥ß¥å¥Ë¥Æ¥£¤Î¥á¥ó¥Ð¡¼¤«¤É¤¦¤«
+        *
+        * @param ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return true / false
+        */
+       static function is_community_member($user_community_id, $community_id) {
+               $sql  = "SELECT count(*)";
+               $sql .= " FROM community, community_member";
+               $sql .= " WHERE community.community_id = '" . pg_escape_string($community_id) . "'";
+               $sql .= "  AND community.community_id = community_member.community_id";
+               $sql .= "  AND community_member.user_community_id = '" . pg_escape_string($user_community_id) . "'";
+
+               $value = ACSDB::_get_value($sql);
+               return intval($value);
+       }
+
+       /**
+        * ¥æ¡¼¥¶¤¬¥³¥ß¥å¥Ë¥Æ¥£¤Î´ÉÍý¼Ô¤«¤É¤¦¤«
+        *
+        * @param DBÀܳ¥ê¥½¡¼¥¹
+        * @param ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return true / false
+        */
+       static function is_community_admin($user_community_id, $community_id) {
+               $sql  = "SELECT count(*)";
+               $sql .= " FROM community, community_member, community_member_type_master";
+               $sql .= " WHERE community.community_id = '" . pg_escape_string($community_id) . "'";
+               $sql .= "  AND community.community_id = community_member.community_id";
+               $sql .= "  AND community_member.user_community_id = '" . pg_escape_string($user_community_id) . "'";
+               $sql .= "  AND community_member.community_member_type_code = community_member_type_master.community_member_type_code";
+               $sql .= "  AND community_member_type_master.community_member_type_name = '".ACSMsg::get_mst('community_member_type_master','D10')."'";
+
+               $value = ACSDB::_get_value($sql);
+               return intval($value);
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥«¥Æ¥´¥ê¥°¥ë¡¼¥×°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @return ¥«¥Æ¥´¥ê¥°¥ë¡¼¥×°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_category_group_master_row_array() {
+               $sql  = "SELECT *";
+               $sql .= " FROM category_group_master";
+               $sql .= " ORDER BY category_group_code ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥«¥Æ¥´¥ê¥°¥ë¡¼¥×¤ò»ØÄꤷ¤Æ¥«¥Æ¥´¥ê°ìÍ÷¤ò¼èÆÀ¤¹¤ë
+        *
+        * @param $category_group_code ¥«¥Æ¥´¥ê¥°¥ë¡¼¥×¥³¡¼¥É
+        * @return ¥«¥Æ¥´¥ê°ìÍ÷ (Ï¢ÁÛÇÛÎó¤ÎÇÛÎó)
+        */
+       static function get_category_master_row_array_by_category_group_code($category_group_code) {
+               $category_group_code = pg_escape_string($category_group_code);
+
+               $sql  = "SELECT category_code, category_name";
+               $sql .= " FROM category_master";
+               $sql .= " WHERE category_master.category_group_code = '$category_group_code'";
+               $sql .= " ORDER BY category_master.category_code ASC";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤Î¥«¥Æ¥´¥ê¥³¡¼¥É¤´¤È¤Î·ï¿ô¤ò¼èÆÀ¤¹¤ë
+        *
+        * @return ¥«¥Æ¥´¥ê¥³¡¼¥É¤ò¥­¡¼¤Ë¤·¤¿·ï¿ô¤ÎÇÛÎó
+        */
+       static function get_category_code_community_num_array() {
+               $ret_array = array();
+
+               $sql  = "SELECT community.category_code, count(*) as community_num";
+               $sql .= " FROM community, category_master";
+               $sql .= " WHERE community.category_code = category_master.category_code";
+               $sql .= " GROUP BY community.category_code";
+               $sql .= " ORDER BY community.category_code";
+               $row_array = ACSDB::_get_row_array($sql);
+
+               foreach ($row_array as $row) {
+                       $ret_array[$row['category_code']] = $row['community_num'];
+               }
+
+               return $ret_array;
+       }
+
+
+       /*
+        * ¥³¥ß¥å¥Ë¥Æ¥£»²²Ã¤Î¾µÇ§¤¬É¬Íפ«¤É¤¦¤«
+        *
+        * @param $user_community_id ¥æ¡¼¥¶¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @param $community_id ¥³¥ß¥å¥Ë¥Æ¥£ID
+        * @return ¾µÇ§¤¬É¬Í×(true) / ¼«Í³»²²Ã(false)
+        */
+       static function is_admission_required_for_join_community($user_community_id, $community_id) {
+               // ¾µÇ§É¬Íץե饰
+               $is_admission_required = true;
+
+               // ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó
+               $community_row = ACSCommunity::get_community_row($community_id);
+
+               // ¼«Í³»²²Ã²Äǽ¥³¥ß¥å¥Ë¥Æ¥£
+               $join_trusted_community_row_array = ACSCommunity::get_join_trusted_community_row_array($community_id);
+
+               // ¥Þ¥¤¥³¥ß¥å¥Ë¥Æ¥£
+               $my_community_row_array = ACSUser::get_community_row_array($user_community_id);
+               $my_community_id_array = array();
+               foreach ($my_community_row_array as $my_community_row) {
+                       array_push($my_community_id_array, $my_community_row['community_id']);
+               }
+
+               if (!ACSLib::get_boolean($community_row['admission_flag'])) {
+                       // ¾µÇ§¥Õ¥é¥°¤¬f¤Ê¤é¼«Í³»²²Ã
+                       $is_admission_required = false;
+               } else {
+                       // ¥Þ¥¤¥³¥ß¥å¥Ë¥Æ¥£¤¬¼«Í³»²²Ã²Äǽ¥³¥ß¥å¥Ë¥Æ¥£°ìÍ÷¤Ë´Þ¤Þ¤ì¤ë¤«
+                       foreach ($join_trusted_community_row_array as $join_trusted_community_row) {
+                               //if (array_search($join_trusted_community_row['community_id'], $my_community_id_array)) {
+                               if (in_array($join_trusted_community_row['community_id'], $my_community_id_array)) {
+                                       $is_admission_required = false;
+                                       break;
+                               }
+                       }
+               }
+
+               return $is_admission_required;
+       }
+
+
+       /**
+        * ¥Ç¥Õ¥©¥ë¥È¤Î URL ¤òÊÖ¤¹
+        *
+        * @param view_mode    É½¼¨¥â¡¼¥É : NULL, thumb, rss
+        */
+       static function get_default_image_url ($view_mode) {
+               if ($view_mode == 'thumb') {
+                       return ACS_DEFAULT_COMMUNITY_IMAGE_FILE_THUMB;
+               } else {
+                       return ACS_DEFAULT_COMMUNITY_IMAGE_FILE;
+               }
+       }
+
+       /**
+        * image_url¤ò²Ã¹©¤¹¤ë
+        *
+        * @param community_id
+        * @param view_mode    É½¼¨¥â¡¼¥É : NULL, thumb, rss
+        */
+       static function get_image_url($community_id, $view_mode = '') {
+               $file_id = ACSCommunityImageFileModel::get_file_id($community_id);
+
+               if ($file_id != '') {
+                       $image_url  = SCRIPT_PATH . '?';
+                       $image_url .= MODULE_ACCESSOR . '=Community';
+                       $image_url .= '&' . ACTION_ACCESSOR . '=CommunityImage';
+                       $image_url .= '&community_id=' . $community_id;
+                       $image_url .= '&mode=' . $view_mode;
+               } else {
+                       $image_url = ACSCommunity::get_default_image_url($view_mode);
+               }
+
+               return $image_url;
+       }
+       
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤òÊ£¿ô¼èÆÀ¤¹¤ë
+        *
+        * @param $community_id_array ¥³¥ß¥å¥Ë¥Æ¥£IDÇÛÎó
+        * @return ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó¤ÎÇÛÎó
+        */
+       static function get_each_community_row_array($community_row_array) {
+               if (count($community_row_array)) {
+                       $community_id_csv = implode(',', $community_row_array);
+               } else {
+                       $community_id_csv = 'null';
+               }
+               $sql  = "SELECT *";
+               $sql .= " FROM ((community LEFT OUTER JOIN category_master ON community.category_code = category_master.category_code)";
+               $sql .= "  LEFT OUTER JOIN community_image_file USING(community_id)) as JOINED_COMMUNITY,"; 
+               $sql .= "  community_type_master";
+               $sql .= " WHERE JOINED_COMMUNITY.community_id IN( " .$community_id_csv ." )";
+               $sql .= "  AND JOINED_COMMUNITY.community_type_code = community_type_master.community_type_code";
+
+               $row_array = ACSDB::_get_row_array($sql);
+               return $row_array;
+       }
+
+       /**
+        * ¥³¥ß¥å¥Ë¥Æ¥£¤ò¹¹¿·¤¹¤ë
+        * 2006/3/9
+        * @param $form ¥³¥ß¥å¥Ë¥Æ¥£¾ðÊó
+        * return À®¸ù(¥³¥ß¥å¥Ë¥Æ¥£ID) / ¼ºÇÔ(false)
+        */
+       static function update_community($form) {
+               // ¥³¥ß¥å¥Ë¥Æ¥£¼ïÊÌ¥Þ¥¹¥¿
+               $community_type_master_array = ACSDB::get_master_array('community_type');
+               $community_type_code = array_search(ACSMsg::get_mst('community_type_master','D40'), $community_type_master_array);
+               // ¥³¥ó¥Æ¥ó¥Ä¼ïÊÌ¥Þ¥¹¥¿
+               $contents_type_master_array = ACSDB::get_master_array('contents_type');
+               // ¥³¥ß¥å¥Ë¥Æ¥£¥á¥ó¥Ð¼ïÊÌ¥Þ¥¹¥¿
+               $community_member_type_master_array = ACSDB::get_master_array('community_member_type');
+               $community_id_seq = $form['community_id'];
+               $org_form = $form;
+
+               ACSLib::escape_sql_array($form);
+               ACSLib::get_sql_value_array($form);
+
+               // BEGIN
+               ACSDB::_do_query("BEGIN");
+
+               // (1) ¥³¥ß¥å¥Ë¥Æ¥£ (community)
+               $admission_flag = ACSLib::get_pg_boolean($org_form['admission_flag']);
+               $sql  = "UPDATE community";
+               $sql .= " SET community_name = $form[community_name],";
+               $sql .= " category_code = $form[category_code],";
+               $sql .= " admission_flag = $form[admission_flag]";
+               $sql .= " WHERE community_id = $community_id_seq";
+               $ret = ACSDB::_do_query($sql);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (2) ¥³¥ß¥å¥Ë¥Æ¥£¥×¥í¥Õ¥£¡¼¥ë
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D07'), $contents_type_master_array);
+               $contents_form['contents_value'] = $org_form['community_profile'];
+               $contents_form['open_level_code'] = ACSAccessControl::get_default_open_level_code(ACSMsg::get_mst('community_type_master','D40'), ACSMsg::get_mst('contents_type_master','D07'));
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               
+
+               // (3) »²²Ã»ñ³Ê (join_trusted_community)
+               $join_trusted_community_form = array();
+               $join_trusted_community_form['community_id'] = $community_id_seq;
+               // join_trusted_community Á°½àÈ÷¡¡µì¥Ç¡¼¥¿¤Î°ì³çºï½ü
+               $ret = ACSCommunity::delete_join_trusted_community($join_trusted_community_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               //ÅÐÏ¿
+               if (is_array($org_form['join_trusted_community_id_array'])) {
+                       foreach ($org_form['join_trusted_community_id_array'] as $trusted_community_id) {
+                               $join_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_join_trusted_community($join_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (4) ¸ø³«ÈÏ°Ï ÅŻҷǼ¨ÈÄ
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D41'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['bbs_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               // contents_trusted_community
+               if (is_array($org_form['bbs_trusted_community_id_array'])) {
+                       $contents_trusted_community_form = array();
+                       $contents_trusted_community_form['community_id'] = $community_id_seq;
+                       $contents_trusted_community_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D41'), $contents_type_master_array);
+                       $contents_trusted_community_form['open_level_code'] = $org_form['bbs_open_level_code'];
+               // contents_trusted_community Á°½àÈ÷¡¡µì¥Ç¡¼¥¿¤Î°ì³çºï½ü
+                       $ret = ACSCommunity::update_contents_trusted_community($contents_trusted_community_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+               //ÅÐÏ¿
+                       foreach ($org_form['bbs_trusted_community_id_array'] as $trusted_community_id) {
+                               $contents_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_contents_trusted_community($contents_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (5) ¸ø³«ÈÏ°Ï ¥³¥ß¥å¥Ë¥Æ¥£¥Õ¥©¥ë¥À (cotents)
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D31'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['community_folder_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+               // contents_trusted_community
+               if (is_array($org_form['community_folder_trusted_community_id_array'])) {
+                       $contents_trusted_community_form = array();
+                       $contents_trusted_community_form['community_id'] = $community_id_seq;
+                       $contents_trusted_community_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D31'), $contents_type_master_array);
+                       $contents_trusted_community_form['open_level_code'] = $org_form['community_folder_open_level_code'];
+               // contents_trusted_community Á°½àÈ÷¡¡µì¥Ç¡¼¥¿¤Î°ì³çºï½ü
+                       $ret = ACSCommunity::update_contents_trusted_community($contents_trusted_community_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+               // ÅÐÏ¿
+                       foreach ($org_form['community_folder_trusted_community_id_array'] as $trusted_community_id) {
+                               $contents_trusted_community_form['trusted_community_id'] = $trusted_community_id;
+                               $ret = ACSCommunity::set_contents_trusted_community($contents_trusted_community_form);
+                               if (!$ret) {
+                                       ACSDB::_do_query("ROLLBACK");
+                                       return $ret;
+                               }
+                       }
+               }
+
+               // (6) ¸ø³«ÈÏ°Ï Á´ÂÎ
+               // contents
+               $contents_form = array();
+               $contents_form['community_id'] = $community_id_seq;
+               $contents_form['contents_type_code'] = array_search(ACSMsg::get_mst('contents_type_master','D00'), $contents_type_master_array);
+               $contents_form['contents_value'] = '';
+               $contents_form['open_level_code'] = $org_form['self_open_level_code'];
+               $ret = ACSCommunity::set_contents($contents_form);
+               if (!$ret) {
+                       ACSDB::_do_query("ROLLBACK");
+                       return $ret;
+               }
+
+               // (7) ¥³¥ß¥å¥Ë¥Æ¥£ML
+               // contents
+               // ¥³¥ß¥å¥Ë¥Æ¥£ML¥¢¥É¥ì¥¹
+               if ($org_form['community_ml_address']) {
+                       $contents_form = array();
+                       $contents_form['community_id'] = $community_id_seq;
+                       $contents_form['contents_type_code'] = 
+                                       array_search(ACSMsg::get_mst('contents_type_master','D61'), 
+                                       $contents_type_master_array);
+                       $contents_form['contents_value'] = $org_form['community_ml_address'];
+                       $contents_form['open_level_code'] = 
+                                       ACSAccessControl::get_default_open_level_code(
+                                               ACSMsg::get_mst('community_type_master','D40'), 
+                                               ACSMsg::get_mst('contents_type_master','D61'));
+                       $ret = ACSCommunity::set_contents($contents_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+                       // ¥³¥ß¥å¥Ë¥Æ¥£ML¥¹¥Æ¡¼¥¿¥¹
+                       $contents_form = array();
+                       $contents_form['community_id'] = $community_id_seq;
+                       $contents_form['contents_type_code'] = 
+                                       array_search(ACSMsg::get_mst('contents_type_master','D62'), 
+                                       $contents_type_master_array);
+                       $contents_form['contents_value'] = 'QUEUE';
+                       $contents_form['open_level_code'] = 
+                                       ACSAccessControl::get_default_open_level_code(
+                                               ACSMsg::get_mst('community_type_master','D40'), 
+                                               ACSMsg::get_mst('contents_type_master','D62'));
+                       $ret = ACSCommunity::set_contents($contents_form);
+                       if (!$ret) {
+                               ACSDB::_do_query("ROLLBACK");
+                               return $ret;
+                       }
+               }
+
+               // COMMIT
+               ACSDB::_do_query("COMMIT");
+
+               return $community_id_seq;
+       }
+
+       /**
+        * ML¥¢¥É¥ì¥¹¤Î¸ºß¥Á¥§¥Ã¥¯
+        * @param $ml_addr ¥á¡¼¥ë¥¢¥É¥ì¥¹
+        * return boolean true...´û¤Ë¸ºß/false...¸ºß¤·¤Ê¤¤
+        */
+       static function is_exists_ml_addr($ml_addr) {
+               $sql  = "SELECT count(*) AS cnt FROM contents " .
+                               "WHERE contents_type_code = '61' " .
+                               "AND contents_value = '" . pg_escape_string($ml_addr) ."'";
+               $row = ACSDB::_get_row($sql);
+               return ($row['cnt']>0 ? TRUE : FALSE);
+       }
+}
+?>