source: branches/1.2/content/plugins/autoreader/templates/autoreader_list.php @ 1334

Revision 1334, 8.3 KB checked in by shibuya246, 3 years ago (diff)

[branch 1.2] latest changes for current version

Line 
1<?php
2    require_once(PLUGINS . 'autoreader/autoreader.php');
3    $arSettings = new Autoreader($h);
4    $campaigns = $arSettings->getCampaigns($h);
5
6    $action = $h->cage->post->testAlnumLines('action');
7
8
9     switch ($action) {
10        case "fetch":           
11            $fetched= $arSettings->adminForcefetch($h);
12            $array = array('fetched'=> $fetched);
13            echo json_encode($array);
14            exit;
15        case "delete":
16            $result = $arSettings->adminDelete($h);
17            echo $result;
18            exit;
19        case "reset":
20            $result = $arSettings->adminReset($h);
21            echo $result;
22            exit;
23     default :
24         //print "default";
25
26    }
27
28 ?>
29
30  <div class="wrap">
31    <h2>Campaigns</h2>     
32 
33    <table class="widefat">
34      <thead>
35        <tr>
36          <th scope="col" style="text-align: center">ID</th>
37          <th scope="col">Title</th>
38          <th style="text-align: center" scope="col">Active</th>
39          <th style="text-align: center" scope="col">Total Posts</th>
40          <th scope="col">Last Active</th>
41          <th scope="col" colspan="4" style="text-align: center">Actions</th>
42        </tr>
43      </thead>
44     
45      <tbody id="the-list">           
46        <?php if(!$campaigns): ?>
47          <tr>
48            <td colspan="5">No campaigns to display</td>
49          </tr> 
50        <?php else: ?>     
51          <?php $class = ''; ?> 
52         
53          <?php foreach($campaigns as $campaign): ?>
54          <?php $class = ('alternate' == $class) ? '' : 'alternate'; ?>             
55          <tr id='campaign-<?php echo $campaign->id ?>' class='<?php echo $class ?> <?php if($h->cage->get->getInt('id') == $campaign->id) echo 'highlight'; ?>'>
56            <th scope="row" style="text-align: center"><?php echo $campaign->id ?></th>
57            <td><?php echo $campaign->title; ?></td>
58            <td style="text-align: center"><?php if ($campaign->active) {echo 'Yes'; } else {echo 'No';}  ?></td>
59            <td style="text-align: center"><?php echo $campaign->count ?></td>       
60            <td><?php echo $campaign->lastactive?></td>
61            <td><?php echo "<a id='edit_" . $campaign->id . "' href='#' class='edit'>Edit</a></td>"; ?>
62            <td><?php echo "<a id='fetch_" . $campaign->id . "' href='#' class='fetch' >" .'Fetch' . "</a>"; ?></td>
63            <td><?php echo "<a id='reset_" . $campaign->id . "' href='#' class='reset' >" .'Reset' . "</a>"; ?></td>
64            <td><a href="#" id="delete_<?php echo $campaign->id; ?>" class="delete">Delete</a></td>
65          </tr>             
66          <?php endforeach; ?>                   
67        <?php endif; ?>
68      </tbody>
69    </table>
70           
71  </div>
72
73 <script type='text/javascript'>
74    jQuery('document').ready(function($) {
75
76        $('.delete').click(function(){
77            var answer = confirm('You are about to delete the campaign. This action does not remove campaign generated posts. Delete ? '+jQuery(this).attr('title'));           
78            if (answer) {
79                var campign_ref = $(this).attr('id').split('_');
80                var campaign_id = campign_ref[campign_ref.length-1];
81                var formdata = 'action=delete&s=delete&id=' + campaign_id;
82                var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_list';
83
84                 $.ajax(
85                    {
86                    type: 'post',
87                    url: sendurl,
88                    data: formdata,
89                    error:      function(XMLHttpRequest, textStatus, errorThrown) {
90                                    $('#delete_' + campaign_id).html('ERR');
91                    },
92                    success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg
93                            if (data.error === true) {
94                            }
95                            else
96                            {
97                                $('#delete_' + campaign_id).parent().parent().delay(1000).addClass('red').fadeOut(2000);
98                            }
99                    },
100                    dataType: "json"
101                });
102            }
103            return false;
104            });
105
106         $('.reset').click(function(){
107            var answer = confirm('Are you sure you want to reset this campaign? Resetting does not affect already created posts ? '+jQuery(this).attr('title'));
108            if (answer) {
109            var campign_ref = $(this).attr('id').split('_');
110                var campaign_id = campign_ref[campign_ref.length-1];
111                var formdata = 'action=reset&s=reset&id=' + campaign_id;
112                var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_list';
113
114                 $.ajax(
115                    {
116                    type: 'post',
117                    url: sendurl,
118                    data: formdata,
119                    error:      function(XMLHttpRequest, textStatus, errorThrown) {
120                                    $('#reset_' + campaign_id).html('ERR');
121                    },
122                    success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg
123                            if (data.error === true) {
124                            }
125                            else
126                            {
127                                $('#reset_' + campaign_id).parent().parent().addClass('yellow');
128                            }
129                    },
130                    dataType: "json"
131                });
132            }
133            return false;
134            });
135
136        $(".fetch").click(function() {
137         var answer = confirm('Are you sure you want to process all feeds from this campaign? '+jQuery(this).attr('title'));
138            if (answer) {
139
140            var campign_ref = $(this).attr('id').split('_');
141            var campaign_id = campign_ref[campign_ref.length-1];
142            var formdata = 'action=fetch&s=forcefetch&id=' + campaign_id;
143            var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_list';
144
145            $.ajax(
146                {
147                type: 'post',
148                url: sendurl,
149                data: formdata,
150                beforeSend: function () {
151                                $('#fetch_' + campaign_id).html('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/ajax-loader.gif' + '"/>');
152                        },
153                error:  function(XMLHttpRequest, textStatus, errorThrown) {
154                                $('#fetch_' + campaign_id).html('ERR');
155                },
156                success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg
157                        if (data.error === true) {
158                        }
159                        else
160                        {
161                            $('#fetch_' + campaign_id).html(data.fetched);
162                        }
163                },
164                dataType: "json"
165            });
166        }
167        return false;
168       });
169
170
171       $(".edit").click(function(event) {
172        event.preventDefault();       
173        var campign_ref = $(this).attr('id').split('_');
174        var campaign_id = campign_ref[campign_ref.length-1];       
175        var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_add&action=edit&id=' + campaign_id;
176
177        $("#admin_plugin_content")
178                .fadeOut("fast")
179                .text("... loading ...")
180                .load(sendurl)
181                .fadeIn("fast");
182
183
184        return false;
185       });
186
187        $(".delete").click(function(event) {
188        event.preventDefault();
189        var campign_ref = $(this).attr('id').split('_');
190        var campaign_id = campign_ref[campign_ref.length-1];
191        var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_list&action=delete&id=' + campaign_id;
192
193        return false;
194       });
195
196
197
198     });
199 </script>
200 
Note: See TracBrowser for help on using the repository browser.