ここの情報は古いです。ご理解頂いた上でお取り扱いください。

source: OpenPNE/branches/stable-2.10.x/webapp/modules/pc/do/c_topic_edit_update_c_commu_topic.php @ 5232

Last change on this file since 5232 was 5232, checked in by ebihara, 15 years ago

#1217:否定演算子のつけ忘れを修正

File size: 5.6 KB
Line 
1<?php
2/**
3 * @copyright 2005-2007 OpenPNE Project
4 * @license   http://www.php.net/license/3_01.txt PHP License 3.01
5 */
6
7class pc_do_c_topic_edit_update_c_commu_topic extends OpenPNE_Action
8{
9    function execute($requests)
10    {
11        $u = $GLOBALS['AUTH']->uid();
12
13        // --- リクエスト変数
14        $c_commu_topic_id = $requests['target_c_commu_topic_id'];
15        $body = $requests['body'];
16        $title = $requests['title'];
17        // ----------
18        $upfile_obj1 = $_FILES['image_filename1'];
19        $upfile_obj2 = $_FILES['image_filename2'];
20        $upfile_obj3 = $_FILES['image_filename3'];
21        $upfile_obj4 = $_FILES['filename4'];
22
23        //--- 権限チェック
24        //トピック作成者 or コミュニティ管理者
25
26        $c_topic = c_topic_detail_c_topic4c_commu_topic_id($c_commu_topic_id);
27        $c_commu_id = $c_topic['c_commu_id'];
28
29        if (!db_commu_is_c_topic_admin($c_commu_topic_id, $u) &&
30            !db_commu_is_c_commu_admin($c_commu_id, $u)) {
31            handle_kengen_error();
32        }
33        $c_commu = db_commu_c_commu4c_commu_id2($c_commu_id);
34        if ($c_commu['topic_authority'] == 'admin_only' &&
35            !db_commu_is_c_commu_admin($c_commu_id, $u)) {
36            handle_kengen_error();
37        }
38        //---
39
40        //エラーチェック
41        $err_msg = array();
42        if (is_null($title) || $title === '') $err_msg[] = "タイトルを入力してください";
43        if (is_null($body) || $body === '') $err_msg[] = "詳細を入力してください";
44
45        if (!empty($upfile_obj1) && $upfile_obj1['error'] !== UPLOAD_ERR_NO_FILE) {
46            if (!($image = t_check_image($upfile_obj1))) {
47                $err_msg[] = '画像1は'.IMAGE_MAX_FILESIZE.'KB以内のGIF・JPEG・PNGにしてください';
48            }
49        }
50        if (!empty($upfile_obj2) && $upfile_obj2['error'] !== UPLOAD_ERR_NO_FILE) {
51            if (!($image = t_check_image($upfile_obj2))) {
52                $err_msg[] = '画像2は'.IMAGE_MAX_FILESIZE.'KB以内のGIF・JPEG・PNGにしてください';
53            }
54        }
55        if (!empty($upfile_obj3) && $upfile_obj3['error'] !== UPLOAD_ERR_NO_FILE) {
56            if (!($image = t_check_image($upfile_obj3))) {
57                $err_msg[] = '画像3は'.IMAGE_MAX_FILESIZE.'KB以内のGIF・JPEG・PNGにしてください';
58            }
59        }
60
61        if (OPENPNE_USE_FILEUPLOAD) {
62            if (!empty($upfile_obj4) && $upfile_obj4['error'] !== UPLOAD_ERR_NO_FILE) {
63                // ファイルサイズ制限
64                if ($upfile_obj4['size'] === 0 || $upfile_obj4['size'] > FILE_MAX_FILESIZE * 1024) {
65                    $err_msg[] = 'ファイルは' . FILE_MAX_FILESIZE . 'KB以内のファイルにしてください(ただし空のファイルはアップロードできません)';
66                }
67
68                // 拡張子制限
69                if (!util_check_file_extention($upfile_obj4['name'])) {
70                    $err_msg[] = sprintf('アップロードできるファイルの種類は(%s)です', util_get_file_allowed_extensions('string'));
71                }
72            }
73        }
74
75        if ($err_msg) {
76            $_REQUEST['err_msg'] = $err_msg;
77            $_REQUEST['target_c_commu_topic_id'] = $c_commu_topic_id;
78            $_REQUEST['title'] = $title;
79            $_REQUEST['body'] = $body;
80            openpne_forward('pc', 'page', "c_topic_edit");
81            exit;
82        }
83
84        //画像コピー
85        $sessid = session_id();
86        t_image_clear_tmp($sessid);
87        $tmpfile1 = t_image_save2tmp($upfile_obj1, $sessid, "t_1");
88        $tmpfile2 = t_image_save2tmp($upfile_obj2, $sessid, "t_2");
89        $tmpfile3 = t_image_save2tmp($upfile_obj3, $sessid, "t_3");
90        if (OPENPNE_USE_FILEUPLOAD) {
91            $tmpfile4 = t_file_save2tmp($upfile_obj4, $sessid, "t_4");
92        }
93
94        if ($tmpfile1) {
95            $filename1 = image_insert_c_image4tmp("t_{$c_commu_topic_id}_1", $tmpfile1);
96        }
97        if ($tmpfile2) {
98            $filename2 = image_insert_c_image4tmp("t_{$c_commu_topic_id}_2", $tmpfile2);
99        }
100        if ($tmpfile3) {
101            $filename3 = image_insert_c_image4tmp("t_{$c_commu_topic_id}_3", $tmpfile3);
102        }
103        if ($tmpfile4) {
104            $filename4 = file_insert_c_file4tmp("t_{$c_commu_topic_id}_4", $tmpfile4, $upfile_obj4['name']);
105        }
106        t_image_clear_tmp(session_id());
107        t_file_clear_tmp(session_id());
108
109
110        $update_c_commu_topic = array(
111            'name'       => $title,
112            'event_flag' => 0,
113        );
114        db_commu_update_c_commu_topic($c_commu_topic_id, $update_c_commu_topic);
115
116
117        $update_c_commu_topic_comment = array(
118            'body' => $body,
119        );
120        $c_topic = db_commu_c_topic4c_commu_topic_id($c_commu_topic_id);
121        if ($filename1) {
122            $update_c_commu_topic_comment["image_filename1"] = $filename1;
123            image_data_delete($c_topic['image_filename1']);
124        }
125        if ($filename2) {
126            $update_c_commu_topic_comment["image_filename2"] = $filename2;
127            image_data_delete($c_topic['image_filename2']);
128        }
129        if ($filename3) {
130            $update_c_commu_topic_comment["image_filename3"] = $filename3;
131            image_data_delete($c_topic['image_filename3']);
132        }
133        if ($filename4) {
134            $update_c_commu_topic_comment['filename4'] = $filename4;
135            db_file_delete_c_file($c_topic['filename']);
136        }
137        db_commu_update_c_commu_topic_comment($c_commu_topic_id, $update_c_commu_topic_comment);
138
139        $p = array('target_c_commu_topic_id' => $c_commu_topic_id);
140        openpne_redirect('pc', 'page_c_topic_detail', $p);
141    }
142}
143
144?>
Note: See TracBrowser for help on using the repository browser.