Project

General

Profile

1
<?php
2

    
3
    $aJsonRespond = [];
4
    $sModuleDir   = basename(dirname(__DIR__));
5
    // require config for Constants and DB access
6
    require(dirname(dirname(dirname(__DIR__))).'/config.php');
7
    // Check if user has enough rights to do this:
8
    // initialize json_respond array  (will be sent back)
9
    try{
10
        if (!class_exists('admin', false)){require(WB_PATH.'/framework/class.admin.php');}
11
        $admin = new admin('Modules', 'module_view', FALSE, FALSE);
12
    // first read and validate the $_POST arguments
13
        $aAllowedActions = ['toggle_active_status'];
14
        $sRequestAction  = $_POST['action'] ?:'';
15
        // test if action value is in allowed list of actions
16
        if ( !in_array($sRequestAction, $aAllowedActions)) {
17
            throw new Exception('no valid "action" was set');
18
        }
19
        $sRequestIdKey = $_POST['iRecordId'];
20
//        $iIdKey = $admin->checkIDKEY('iRecordId');
21
//        $iIdKey = $admin->checkIDKEY('iRecordId', 0, '', true);
22
        $iIdKey = $sRequestIdKey;
23
        if (!($iRequestRecordId = (int)$iIdKey ?: 0)) {
24
            throw new Exception('no valid RecordId was set '.$iRequestRecordId);
25
        }
26
        if (!($admin->is_authenticated() && $admin->get_permission($sModuleDir, 'module'))) {
27
            throw new Exception('You\'re not allowed to make changes to Module: ['.$sModuleDir.']');
28
        }
29
        switch ($sRequestAction):
30
            case 'toggle_active_status':
31
                // Check the Parameters
32
                $sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` SET '
33
                     . '`active`= (`active` IS NOT TRUE) '
34
                     . 'WHERE `post_id`='.$iRequestRecordId;
35
                if (!(bool)$database->query($sql)) {
36
                    throw new Exception('DB access fail ['.$database->get_error().']');
37
                }
38
                break;
39
            default:
40
                throw new Exception('no valid "action" was set ');
41
                break;
42
        endswitch;
43
        $aJsonRespond['message'] = 'Activity Status successfully changed';
44
        $aJsonRespond['success'] = true;
45
//        $aJsonRespond['sIdKey']  = $admin->getIDKEY($iIdKey);
46
        $aJsonRespond['sIdKey']  = $iIdKey;
47
    } catch (Exception $e) {
48
        $aJsonRespond['message'] = $e->getMessage();
49
        $aJsonRespond['success'] = false;
50
//        $aJsonRespond['sIdKey']  = $admin->getIDKEY($iIdKey);
51
        $aJsonRespond['sIdKey']  = $iIdKey;
52
    }
53
    // echo the json_respond to the ajax function
54
    exit(json_encode($aJsonRespond));
(1-1/2)