--- sites/all/modules/achievement_entity/modules/achievement_badges/achievement_badges.module	2012-11-21 16:01:11.000000000 +0530
+++ sites/all/modules/achievement_entity/modules/achievement_badges/achievement_badges.module	2012-11-21 17:23:14.901071000 +0530
@@ -80,40 +80,51 @@
   if ($form_id == 'achievement_entity_form' && $form['#bundle'] == 'badges') {
     unset($form['title']);
     array_unshift($form['actions']['submit']['#submit'], "achievement_badges_title_submit");
-    
-    //set max length for description field in badges.
-    $form['field_badge_entity_description']['und'][0]['value']['#attributes'] = array('onKeyPress'=>"return(this.value.length<$max_length);");
+
+       //badge description limit.
+      $form['#validate'][] = 'achievement_badges_description_validate';
+   
   }
-    //achievements give ,user by admin form
+  //achievements give ,user by admin form
   if ($form_id == 'achievements_settings') {
     $form['achievements_manual']['actions']['achievements_manual_give']['#submit'][] = 'create_unique_badge_images_user';
   }
-  
-  
 }
 /**
+ * To restrict badges description limit not more than 128 charactor.
+ * @param type $form
+ * @param type $form_state 
+ */
+function achievement_badges_description_validate($form, $form_state) { 
+  if ($form_state['clicked_button']['#value'] != 'Delete') {
+    $str = $form['field_badge_entity_description']['und'][0]['value']['#value'];    
+    if (strlen($str) > 128) {      
+      form_set_error('limit', "Description should not more than 128 characters");
+    }
+  }
+}
+
+/**
  *
  * @param string $form
  * @param type $form_state
  * this function create a seprate image for user when badge given by admin using admin form.
  */
-function create_unique_badge_images_user($form, &$form_state){
-	
-	$bid = $form['achievements_manual']['achievements_manual_achievement']['#value'];
-	$uid = $form['achievements_manual']['achievements_manual_user']['#value'];
-	if(!is_numeric($uid)){
-	$uid_from_name = user_load_by_name($uid);
-	$uid = $uid_from_name->uid;
-	}
-		$path_badge = entity_load('achievement_entity', array($bid));
-		$path_key = key($path_badge);
-		$path_array = $path_badge[$path_key];
-		$absoult_path_badge = file_create_url($path_array->field_badge_entity_unlock_image['und'][0]['uri']);
-		$real_path = drupal_realpath($path_array->field_badge_entity_unlock_image['und'][0]['uri']);
-    create_unique_badge_image_user($absoult_path_badge,$uid, $real_path, $bid);
-}
-
+function create_unique_badge_images_user($form, &$form_state) {
 
+  $bid = $form['achievements_manual']['achievements_manual_achievement']['#value'];
+  $uid = $form['achievements_manual']['achievements_manual_user']['#value'];
+  if (!is_numeric($uid)) {
+    $uid_from_name = user_load_by_name($uid);
+    $uid = $uid_from_name->uid;
+  }
+  $path_badge = entity_load('achievement_entity', array($bid));
+  $path_key = key($path_badge);
+  $path_array = $path_badge[$path_key];
+  $absoult_path_badge = file_create_url($path_array->field_badge_entity_unlock_image['und'][0]['uri']);
+  $real_path = drupal_realpath($path_array->field_badge_entity_unlock_image['und'][0]['uri']);
+  create_unique_badge_image_user($absoult_path_badge, $uid, $real_path, $bid);
+}
 
 /**
  * multi-select supportable to entity refrence 
@@ -392,39 +403,40 @@
       ),
   );
 }
+
 /*
  * this function create a duplicate image with metadata for user 
  * 
  * 
  * */
-function create_unique_badge_image_user($path, $uid, $real_path, $bid){
-global $base_url;
-$assertion_path = $base_url.'/assertions/'.$bid.'/'.$uid;
-$path = 'http://beta.openbadges.org/baker?assertion='.$assertion_path;	
-$image_name_extension = explode('.png',$real_path);
-$new_path = $image_name_extension[0].'-'.$uid.'.png';
-
-$image_cach_path = explode('default/files/',$real_path);
-$name_cache = explode('.png',$image_cach_path[1]);
-$catch_path_110 = $image_cach_path[0].'default/files/styles/110_110/public/'.$name_cache[0].'-'.$uid.'.png';
-$catch_path_200 = $image_cach_path[0].'default/files/styles/200_200/public/'.$name_cache[0].'-'.$uid.'.png';
+
+function create_unique_badge_image_user($path, $uid, $real_path, $bid) {
+  global $base_url;
+  $assertion_path = $base_url . '/assertions/' . $bid . '/' . $uid;
+  $path = 'http://beta.openbadges.org/baker?assertion=' . $assertion_path;
+  $image_name_extension = explode('.png', $real_path);
+  $new_path = $image_name_extension[0] . '-' . $uid . '.png';
+
+  $image_cach_path = explode('default/files/', $real_path);
+  $name_cache = explode('.png', $image_cach_path[1]);
+  $catch_path_110 = $image_cach_path[0] . 'default/files/styles/110_110/public/' . $name_cache[0] . '-' . $uid . '.png';
+  $catch_path_200 = $image_cach_path[0] . 'default/files/styles/200_200/public/' . $name_cache[0] . '-' . $uid . '.png';
 
 
-copy($path,$new_path);
-copy($path,$catch_path_110);
+  copy($path, $new_path);
+  copy($path, $catch_path_110);
 //copy($path,$catch_path_200);
 //$image = imagecreatefrompng($new_path);
 //header('Content-Type: image/png');
-
 //imagealphablending($image, true);
 //imagesavealpha($image, true);
 //$white = imagecolorallocate($image, 255, 255, 255);
 //imagecolortransparent($image, $white);
-
 //imagepng($image,$new_path);
-drupal_chmod($new_path);
+  drupal_chmod($new_path);
 //imagedestroy($image);
 }
+
 /**
  * For edit views images.
  * expend uid with image uri.
@@ -434,13 +446,13 @@
 
   switch ($view->name) {
     case 'earned_badges':
-      foreach ($view->result as $key => $value) {     
+      foreach ($view->result as $key => $value) {
         $img_url = $value->field_field_badge_entity_unlock_image[0]['rendered']['#item']['uri'];
         $url = explode('.png', $img_url);
-        
+
         //expend uid
         $new_url = $url[0] . '-' . arg(1) . '.png';
-        
+
         //save new url in existing array
         $value->field_field_badge_entity_unlock_image[0]['rendered']['#item']['uri'] = $new_url;
       }
