Hi all,

i'm building my really first module (i'm not a developer) and i would be grateful to anyone that could help me.
As is my firs attempt, please forgive me any error or stupid things; i'll try to clearly explain what the module do and what it should do, please feel free to answer and suggest anything you might consider useful to get deeper.

The module (actually a simple one) lets a block send sms to authenticated_user loading the page where the block is shown (if he/she has checked the option in the edit profile page).
Here is what i wrote down

<?php
/**
 * hook_block().
 */
function sendsms_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Send sms ');
    return $blocks;
  }
  else if ($op == 'view') {
 //Function invio() to send sms and output a defined text. Much much more work to do!
   function invio()
	{
	global $user;
	profile_load_profile($user); 
	$destination_number=$user->{profile_mobile}; 
	$message_body=($user->name) . ", your sms sent. KeyId: ". randomkeys(6) ." -- staff.mysite.com";
	if (isset($user->{profile_mobileok})&&($user->{profile_mobileok})=='1')  {smsgateway_sendmessage( $destination_number, $message_body); $s='Sms delivered.' ; return $s;	} 
	elseif (($user->{profile_mobileok})=='0') { $t='you have to edit your profile to get sms.'; return $t ;	} 
	}
	switch ($delta) {
      case 0:
        $block['subject'] = t('Promo Sms');
        $block['content'] = invio();
        break;
   
     }
    return $block;
  }
}
?>

And here is what i wrote to generate the random string of 6 char (to identify each message).

<?php
 // random string 
	function randomkeys($length)
  {
   $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
   for($i=0;$i<$length;$i++)
   {
     $key .= $pattern{rand(0,35)};
   }
   return $key;
  }
?>

Now I would like to call variables from the shown node to get mobile phone from node author's profile and also send a message to him (using the smsgateway_sendmessageset function), but i don't know how to do... which function should i use to load node-related variables into the block?

I'm planning to add some more features, but i should learn a lot more before i can do it :)

I would be happy if someone -maybe a more experienced user- might be interested in this functionality and would give some tips to get it done... or maybe build up the module together (??).

many thanks in advance

Tom

Comments

tomsci’s picture

just to start... i've found somethig useful here

http://drupal.org/node/83415

PS. i'm not crazy yet, just thinking about who could have the same probs :)

Dublin Drupaller’s picture

Hi tomsci,

Great work.

A few pointers:

Creating modules Tutorial - If you want to go the full hog and create your own module

Alternatively you could create a user profile snippet that goes into a custom user_profile.tpl.php layout file. The handbook section dealing with customising the user profile nodes - contains a lot of examples that will illustrate how you get the mobile phone number from the users profile you're looking at and other useful examples.

I'm stuck for time at the moment, but, I think there's a lot of applications for your idea..and a lot of other Drupal users would be interested.

e.g. a band site might want to have a "send an SMS to your favourite radio station and ask them to play our song", type thing or a company site might want to have an internal staff-only SMS communiation hub, between a team.

Whichever route you decide, i.e. full module or snippet (I recommend you approach the snippet first and then follow up with the module), post back up here if you run into trouble.

Edited: Actually, it would be really cool if a registered user could receive their username/password via SMS instead of/as well as email.

cheers

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

tomsci’s picture

first, because you give me the chance to say you, personally, THANK YOU for all you are doing here (you already helped me -indirectly- many many times). It's amazing!
second, because you actually give me nice ideas and also a big help to go ahead: I'll probably follow the... xtrasimple-module-way :) using the Creating modules Tutorial you linked me. It is probably a bit harder but "i feel quite comfortable until now".

i'll try to do my best, hoping to have skills and time to get it done (unfortunately, i can't work full time on it).
and - of course - i'll call for help if i'd run into trouble ..so... i'll write here soon! ;)

thank you Dub!

Tom

Dublin Drupaller’s picture

Hi Tom.

No worries re: helping out. good luck with the tutorial. and post back up here if you get stuck.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

tomsci’s picture

hello all,
i'm posting the updated code of the module for two main reasons:

1. have a first feedback from cool users/developers
2. share the code with those ( actually one only :D ) who asked me to do it

here it is! please condider that i'm not a developer nor a php expert and that ... i haven't had the time to "study" dev-guidelines to build modules yet (sorry Dub, busy busy time;)

it still implements only block hook, and it's a very customized version. due to time-saving -and ignorance- i've been working looking at my goal more than standard guidelines (rude, but true); of course i'd do it as quickly as possible.

<?php
/**
 * hook_block().
 */
function promosms_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('SimpleSendSms ');
    return $blocks;
  }
  else if ($op == 'configure') {
  }
  else if ($op == 'save') {
  }
  else if ($op == 'view') {
 //random generator
	function randomkeys($length)
  {
   $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
   for($i=0;$i<$length;$i++)
   {
     $key .= $pattern{rand(0,35)};
   }
   return $key;
  }
  
 // send sms if
   function invio()
	{
    $kk=randomkeys(6);
	global $user;
	profile_load_profile($user);
    $node=node_load(arg(1)); 
	if ($_POST['op'] == t('Submit')) {
    $page_content .= '<p>Text sent. <br/>Save your KeyId. ';
    $page_content .= ' Thanks, <br/> My site Staff.</p>';
	  $messageset = array();
      $messageset['1']['destination_number'] = $user->{profile_cel}; // i used cel instad of mob (in italian "cellulare" = "mobile")
      $messageset['1']['message_body'] = $node->field_promo_sms[0]['value'] . ' KeyId:'. ($user->name) . $kk .'@mysite.com';
      $messageset['2']['destination_number'] = $node->field_mobile[0]['value'];
      $messageset['2']['message_body'] = 'Receiving KeyId Text from :'. ($user->name) . $kk .'@mysite.com';
	$resultcode = smsgateway_sendmessageset( $messageset);
    $connectstring = $resultcode['connectstring'];
    $initialbalance = $resultcode['initialbalance'];
    $response = $resultcode['1'] ." / ". $resultcode['2'];
	return $page_content;
    }
// profile_celok is the check button i used to let users confirm their intention to receive texts
	if (isset($user->{profile_celok})&&($user->{profile_celok})=='1') { 
	  $form[] = array(
		'#type' => 'submit',
		'#value' => t('Submit'),
	  );
  $page_content .= '<p>Get your KeyId on your mobile!</p>' ;
  $page_content .= drupal_get_form('smsgateway_test', $form);
  	}
	elseif (($user->{profile_celok})=='0') 	{ 
	$page_content .='<p>You must edit your profile to receive texts.</p>'; 	
	} 
  return $page_content;
	}
//  standrd code for block
	switch ($delta) {
      case 0:
        $block['subject'] = t('Sms Simple Send');
        $block['content'] = invio();
        break;
   
    }
    return $block;
  }
}
?>

Tommi

PS. i'm considering about posting a project (thanks gmak) for this module, but i would like to correctly use guidelines before

gmak’s picture

Tommi,

First let me say thanks for all your work so far. I'm sure that everyone will have different ideas (because we will all have different needs) about how this could develop, but I thought I'd be the first in line.

1. Should we consider having a 'content type' associated with the module? This would mean that you could create a node (probably something like a very basic 'story' node) which has a limited number of characters allowable in the 'body'. The content would then be in the database and allow for delayed sending or re-sending. You'd also be able to keep a record/log of when messages were sent.

2. Should there be a success/failure log for each message? Most SMS gateway services will return success/failure codes for each message attempt. We should consider whether there is a way to capture these and store them in the database so that it is possible to confirm that a user was sent the message. If a failure is recorded, there may even be a notification that can be sent to the Administrator (or sender) so that they may attempt to resend.

3. There should probably be some sort of interface that would allow the sender to choose which user(s) a message is going to be sent to. This could either be by selecting ACL roles, from a profile field, or by individual selection (checkboxes, or similar).

4. The simple send block is a great way to allow users to send a quick SMS.

5. At present you are allowing users to decide whether to receive SMS, which is a good idea for some. I think there needs to be a facility to allow administrators to choose whether this is an option (a bit like the way user.module allows admins to control whether users can change their username). This would mean that Administrators would have the ability to contact all users (which, in my case, would be an absolute requirement).

I'm going to try to do a visual map of what features might be useful and we can look at how things might proceed.

(This is quite exciting. I feel like a real developer!)

rit_blitz’s picture

Hi,
I was looking for a SMS sending module which could send sms to groups etc..and saw this post.

Is this module posted on drupal.Can the latest code be downloaded from somewhere..

cheers.

OnlyBlue’s picture

Hi, Tom
Great work!
I'm looking for a SMS module.
I installed the SMS Gateway module just now. But I can't make out how to use it.
Dose the module support bulk messages sending? I want to develop a site for students management.
Thanks!

㊣━━^-^o中华人民共和国o^-^━━㊣
┃_________上 网 証 書_________┃
┃     ≈≈≈OnlyBlue≈≈≈    ┃
㊣━━^-^o中华人民共和国o^-^━━㊣