Skip to content

Commit

Permalink
Update Moodle v3.7 y v3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
oesantaa committed Nov 28, 2023
1 parent a34fa34 commit 35ff286
Show file tree
Hide file tree
Showing 44 changed files with 1,593 additions and 20,099 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# LabsMobile-Moodle

![](https://img.shields.io/badge/version-1.0.0-blue.svg)
![](https://img.shields.io/badge/version-1.0.1-blue.svg)

Send SMS messages through the LabsMobile platform and the plugin for Moodle. Sign up to install the plugin, and in seconds you will be able to send SMS messages.

Expand All @@ -19,7 +19,7 @@ Labsmobile API documentation can be found[here][apidocs].

## Requirements

- Moodle v.2x y v.3x. More information at [Moodle.org][moodle].
- Moodle v3.7 y v3.10. More information at [Moodle.org][moodle].
- LabsMobile module for Moodle.
- A user account with LabsMobile. Click on the link to create an account [here][signUp].

Expand All @@ -35,10 +35,10 @@ Labsmobile API documentation can be found[here][apidocs].
- Install the Plugin with the downloaded .ZIP file following the instructions and configuring the plugin type as Blocks.

- At the end of the installation, the plugin configuration screen will be displayed. It is necessary to enter the following information:
*v2.X - v3.6*
- apikey: Unused field. You can leave it blank or enter any value.
*v3.7 - v3.10*
- username: Email that corresponds to the account's registration username.
- password: API token generated from the Security and passwords option of the LabsMobile account.
- sender: Numeric or alphanumeric sender of up to 11 characters (only in countries that allow this functionality).

- Go to the Home screen or the desired section of Moodle to add the SMS Notifier block.

Expand Down
116 changes: 60 additions & 56 deletions block_sms.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/* SMS Notifier Block
* SMS notifier is a one way SMS messaging block that allows managers, teachers and administrators to
* send text messages to their student and teacher.
* @package blocks
* @author: Azmat Ullah, Talha Noor
* @date: 17-Jul-2014
*/

class block_sms extends block_base {

public function init() {
$this->title = get_string('sms', 'block_sms');
}

public function get_content() {
global $CFG, $USER, $COURSE;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->text .= html_writer::link(new moodle_url('/blocks/sms/view.php', array('viewpage' => '2')), get_string('sms_send', 'block_sms')) . '<br>';
$this->content->text .= html_writer::link(new moodle_url('/blocks/sms/view.php', array('viewpage' => '3')), get_string('sms_template', 'block_sms')) . '<br>';
return $this->content;
}

public function has_config() {
return true;
}

public function applicable_formats() {
return array('all' => true);
}

public function instance_allow_config() {
return true;
}

}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/* SMS Notifier Block
* SMS notifier is a one way SMS messaging block that allows managers, teachers and administrators to
* send text messages to their student and teacher.
* @package blocks
* @author: Waqas Ansari
* @date: 21-May-2019
*/
/**
* @copyright 2019 3iLogic <[email protected]>
*/

defined('MOODLE_INTERNAL') || die;

class block_sms extends block_base {

public function init() {
$this->title = get_string('sms', 'block_sms');
}

public function get_content() {
global $CFG, $USER, $COURSE;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->text .= html_writer::link(new moodle_url('/blocks/sms/view.php',
array('viewpage' => '2')),
get_string('sms_send', 'block_sms')) . '<br>';
$this->content->text .= html_writer::link(new moodle_url('/blocks/sms/view.php',
array('viewpage' => '3')),
get_string('sms_template', 'block_sms')) . '<br>';
return $this->content;
}

public function has_config() {
return true;
}
public function applicable_formats() {
return array('all' => true);
}
public function instance_allow_config() {
return true;
}
}
63 changes: 63 additions & 0 deletions classes/clickatell_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/* SMS notifier Block
* SMS notifier is a one way SMS messaging block that allows managers, teachers and administrators to
* send text messages to their student and teacher.
* @package blocks
* @author: Waqas Ansari
* @date: 21-May-2019
*/
/**
* @copyright 2019 3iLogic <[email protected]>
*/
defined('MOODLE_INTERNAL') || die;

class ClickatellAPI {
private $uri;
private $apikey;

public function __construct() {
global $CFG;
$this->uri = "https://platform.clickatell.com/messages/http/send";
$this->apikey = $CFG->block_sms_clickatell_apikey;
$this->uri = $this->uri . "?apiKey=" . $this->apikey;
}

public function send_sms($to, $text) {
$result = $this->trigger_api($to, $text);
$status = false;
try {
$result = json_decode($result, true);
$status = $result["messages"][0]["accepted"] == "true";
} catch (Exception $e) {
";";
}
return $status;
}

private function trigger_api($to, $text) {
$data = "&to={$to}&content=" . urlencode($text);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->uri . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json"));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
70 changes: 70 additions & 0 deletions classes/labsmobile_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/* SMS notifier Block
* SMS notifier is a one way SMS messaging block that allows managers, teachers and administrators to
* send text messages to their student and teacher.
* @package blocks
* @author: Waqas Ansari
* @date: 21-May-2019
*/
/**
* @copyright 2019 3iLogic <[email protected]>
*/
defined('MOODLE_INTERNAL') || die();
class LabsmobileAPI {
private $uri;
private $username;
private $password;
private $sender;

public function __construct() {
global $CFG;
$this->uri = "https://api.labsmobile.com/get/send.php";
$this->username = $CFG->block_sms_labsmobile_username;
$this->password = $CFG->block_sms_labsmobile_password;
$this->sender = $CFG->block_sms_labsmobile_sender;
}

public function send_sms($to, $text) {
$result = $this->trigger_api($to, $text);
$status = false;
if(stripos($result, "<code>") !== FALSE) {
$initpos = stripos($result, "<code>") + 6;
$endpos = stripos($result, "</code>");
$code = substr($result, $initpos, $endpos - $initpos);
if($code == "0") {
$status = true;
}
}
return $status;
}

private function trigger_api($to, $text) {
$ch = curl_init();
$params = "username=" . $this->username .
"&password=" . $this->password .
"&sender=" . $this->sender .
"&msisdn={$to}" .
"&message=" . $text;
curl_setopt($ch, CURLOPT_URL, $this->uri . "?" . $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HEADER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
73 changes: 73 additions & 0 deletions classes/nexmo_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/* SMS notifier Block
* SMS notifier is a one way SMS messaging block that allows managers, teachers and administrators to
* send text messages to their student and teacher.
* @package blocks
* @author: Waqas Ansari
* @date: 21-May-2019
*/
/**
* @copyright 2019 3iLogic <[email protected]>
*/
defined('MOODLE_INTERNAL') || die();
class NexmoAPI {
private $uri;
private $apikey;
private $secretkey;
private $fromnumber;

public function __construct() {
global $CFG;
$this->uri = "https://rest.nexmo.com/sms/json";
$this->apikey = $CFG->block_sms_nexmo_apikey;
$this->secretkey = $CFG->block_sms_nexmo_api_secret;
$this->fromnumber = $CFG->block_sms_nexmo_api_from;
$this->uri = $this->uri . "?api_key=" . $this->apikey . "&api_secret=" . $this->secretkey;
}

public function send_sms($to, $text) {
$result = $this->trigger_api($to, $text);
$status = false;
try {
$result = json_decode($result, true);
$status = $result["messages"][0]["status"] == 0;
} catch (Exception $e) {
";";
}
return $status;
}

private function trigger_api($to, $text) {
$data = "from={$this->fromnumber}&to={$to}&text=".urlencode($text);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded"
)
);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
Loading

0 comments on commit 35ff286

Please sign in to comment.