Subversion Repositories oidplus

Rev

Rev 148 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 148 Rev 150
Line 35... Line 35...
35
        public function action(&$handled) {
35
        public function action(&$handled) {
36
                if (isset($_POST["action"]) && ($_POST["action"] == "com.viathinksoft.freeoid.request_freeoid")) {
36
                if (isset($_POST["action"]) && ($_POST["action"] == "com.viathinksoft.freeoid.request_freeoid")) {
37
                        $handled = true;
37
                        $handled = true;
38
                        $email = $_POST['email'];
38
                        $email = $_POST['email'];
39
 
39
 
40
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
40
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($email));
41
                        if (OIDplus::db()->num_rows($res) > 0) {
41
                        if (OIDplus::db()->num_rows($res) > 0) {
42
                                die(json_encode(array("error" => 'This email address already exists.'))); // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
42
                                die(json_encode(array("error" => 'This email address already exists.'))); // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
43
                        }
43
                        }
44
 
44
 
45
                        if (!oidplus_valid_email($email)) {
45
                        if (!oidplus_valid_email($email)) {
Line 127... Line 127...
127
                                $description .= '<p>More information at <a href="'.htmlentities($url).'">'.htmlentities($url).'</a></p>';
127
                                $description .= '<p>More information at <a href="'.htmlentities($url).'">'.htmlentities($url).'</a></p>';
128
                        }
128
                        }
129
 
129
 
130
                        if (empty($title)) $title = $ra_name;
130
                        if (empty($title)) $title = $ra_name;
131
 
131
 
132
                        if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, ra_email, parent, title, description, confidential, created) values ('".OIDplus::db()->real_escape_string('oid:'.$new_oid)."', '".OIDplus::db()->real_escape_string($email)."', '".OIDplus::db()->real_escape_string('oid:'.OIDplus::config()->getValue('freeoid_root_oid'))."', '".OIDplus::db()->real_escape_string($title)."', '".OIDplus::db()->real_escape_string($description)."', 0, now())")) {
132
                        if (!OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, ra_email, parent, title, description, confidential, created) values (?, ?, ?, ?, ?, 0, now())", array('oid:'.$new_oid, $email, 'oid:'.OIDplus::config()->getValue('freeoid_root_oid'), $title, $description))) {
133
                                $ra->delete();
133
                                $ra->delete();
134
                                die(json_encode(array("error" => OIDplus::db()->error())));
134
                                die(json_encode(array("error" => OIDplus::db()->error())));
135
                        }
135
                        }
136
 
136
 
137
                        // Send delegation report email to admin
137
                        // Send delegation report email to admin
Line 212... Line 212...
212
                        $auth = explode('$',$id)[3];
212
                        $auth = explode('$',$id)[3];
213
 
213
 
214
                        $out['title'] = 'Activate Free OID';
214
                        $out['title'] = 'Activate Free OID';
215
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
215
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png' : '';
216
 
216
 
217
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
217
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = ?", array($email));
218
                        if (OIDplus::db()->num_rows($res) > 0) {
218
                        if (OIDplus::db()->num_rows($res) > 0) {
219
                                $out['icon'] = 'img/error_big.png';
219
                                $out['icon'] = 'img/error_big.png';
220
                                $out['text'] = 'This RA is already registered.'; // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
220
                                $out['text'] = 'This RA is already registered.'; // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
221
                        } else {
221
                        } else {
222
                                if (!OIDplus::authUtils()::validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) {
222
                                if (!OIDplus::authUtils()::validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) {
Line 260... Line 260...
260
        }
260
        }
261
 
261
 
262
        # ---
262
        # ---
263
 
263
 
264
        protected function freeoid_max_id() {
264
        protected function freeoid_max_id() {
265
                $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id like '".OIDplus::db()->real_escape_string('oid:'.OIDplus::config()->getValue('freeoid_root_oid').'.%')."' order by ".OIDplus::db()->natOrder('id'));
265
                $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id like ? order by ".OIDplus::db()->natOrder('id'), array('oid:'.OIDplus::config()->getValue('freeoid_root_oid').'.%'));
266
                $highest_id = 0;
266
                $highest_id = 0;
267
                while ($row = OIDplus::db()->fetch_array($res)) {
267
                while ($row = OIDplus::db()->fetch_array($res)) {
268
                        $arc = substr_count(OIDplus::config()->getValue('freeoid_root_oid'), '.')+1;
268
                        $arc = substr_count(OIDplus::config()->getValue('freeoid_root_oid'), '.')+1;
269
                        $highest_id = explode('.',$row['id'])[$arc];
269
                        $highest_id = explode('.',$row['id'])[$arc];
270
                }
270
                }